{"action":"created","comment":{"url":"https://api.github.com/repos/olgkv/just_ruby/pulls/comments/165572624","pull_request_review_id":93533895,"id":165572624,"diff_hunk":"@@ -0,0 +1,298 @@\n+require_relative 'cargo_train'\n+require_relative 'passenger_train'\n+require_relative 'route'\n+require_relative 'station'\n+require_relative 'cargo_car'\n+require_relative 'passenger_car'\n+\n+class Runner\n+  def initialize\n+    @stations = []\n+    @trains = []\n+    @routes = []\n+  end\n+\n+  def start\n+    loop do\n+      options(menu)\n+    end\n+  end\n+\n+  private\n+\n+  def menu\n+    header('Available actions')\n+    puts '1. Create Station'\n+    puts '2. Create Train'\n+    puts '3. Create Route'\n+    puts '4. Add Station to the existing Route'\n+    puts '5. Remove Station from the existing Route'\n+    puts '6. Assign Route to the Train'\n+    puts '7. Add Car to the Train'\n+    puts '8. Remove Car in the Train'\n+    puts '9. Move Train forward along the Route'\n+    puts '10. Move Train backward along the Route'\n+    puts '11. Show Stations list '\n+    puts '12. Show Trains on the Station '\n+    puts '13. Exit'\n+    gets.to_i\n+  end\n+\n+  def options(item)\n+    case item\n+    when 1\n+      create_station\n+    when 2\n+      create_train\n+    when 3\n+      add_route\n+    when 4\n+      add_station\n+    when 5\n+      remove_station\n+    when 6\n+      assign_route\n+    when 7\n+      add_car_to_train\n+    when 8\n+      remove_car_from_train\n+    when 9\n+      move_train_forward\n+    when 10\n+      move_train_backward\n+    when 11\n+      list_all_stations\n+    when 12\n+      show_trains_on_station\n+    else\n+      exit\n+    end\n+  end\n+\n+  def header(string)\n+    length = string.length + 20\n+    puts '-' * length\n+    puts '*' * 5 + ' ' * 5 + string + ' ' * 5 + '*' * 5\n+    puts '-' * length\n+  end\n+\n+  def create_station\n+    header('Create Station')\n+    print 'Enter station name: '\n+    name = gets.chomp\n+    @stations << station = Station.new(name)\n+    if @stations.include?(station)\n+      puts \"Station #{name} was created\"\n+    else\n+      puts 'Something went wrong'\n+    end\n+  end\n+\n+  def create_train\n+    header('Create Train')\n+    puts 'Select type train:'\n+    puts '1 - Cargo'\n+    puts '2 - Passenger'\n+    case gets.to_i\n+    when 1\n+      @trains << CargoTrain.new\n+    when 2\n+      @trains << PassengerTrain.new\n+    end\n+  end\n+\n+  def add_route\n+    header('Create Route')\n+    if @stations.size < 2\n+      puts \"\\nThere is #{@stations.size} station exist. You should create station.\\n\\n\"\n+      return\n+    end\n+    print_collection(@stations, 'Available stations')\n+    start_station = select_item(@stations, 'Select start station:')\n+    end_station = select_item(@stations, 'Select end station:')\n+    @routes << Route.new(start_station, end_station)\n+  end\n+\n+  def add_station\n+    header('Add station')\n+    if @routes.empty?\n+      puts 'There is no route. You should create it'\n+      return\n+    end\n+    if @stations.size <= 2\n+      puts \"\\nThere is only #{@stations.size} station exist. You should create station.\\n\\n\"\n+      return\n+    end\n+    print_collection(@routes, 'Available routes')\n+    route = select_item(@routes, 'Select route: ')\n+    print_collection(@stations, 'Available stations')\n+    station = select_item(@stations, 'Select station:')\n+    route.add_station(station)\n+  end\n+\n+  def remove_station\n+    header('Remove station')\n+    if @routes.empty?\n+      puts 'There is no route. You should create it'\n+      return\n+    end\n+    if @stations.size <= 2\n+      puts \"\\nThere is #{@stations.size} station exist. You should create station, before delete it.\\n\\n\"\n+      return\n+    end\n+    print_collection(@routes, 'Available routes')\n+    route = select_item(@routes, 'Select route:')\n+    print_collection(@stations, 'Available stations')\n+    station = select_item(@stations, 'Select station:')\n+    route.remove_station(station)\n+  end\n+\n+  def assign_route\n+    header('Assign Route')\n+    if @routes.empty?\n+      puts 'There is no route. You should create it'\n+      return\n+    end\n+\n+    if @trains.empty?\n+      puts 'There is no train. You should create it'\n+      return\n+    end\n+    print_collection(@trains, 'Available trains')\n+    train = select_item(@trains, 'Select train:')\n+    print_collection(@routes, 'Available routes')\n+    route = select_item(@routes, 'Select route:')\n+\n+    train.route=route\n+  end\n+\n+  def add_car_to_train\n+    header('Add Car to the Train')\n+    if @trains.empty?\n+      puts 'There is no train. You should create it'\n+      return\n+    end\n+    print_collection(@trains, 'Available trains')\n+    train = select_item(@trains, 'Select train:')\n+    if train.type == 'cargo'\n+      train.add_car(CargoCar.new)\n+    else\n+      train.add_car(PassengerCar.new)\n+    end\n+    print_collection(train.cars, \"#{train.cars.size} cars on the #{train.to_s} train\")\n+  end\n+\n+  def remove_car_from_train\n+    header('Remove Car from the Train')\n+    if @trains.empty?\n+      puts 'There is no train. You should create it'\n+      return\n+    end\n+    print_collection(@trains, 'Available trains')\n+    train = select_item(@trains, 'Select train:')\n+    if train.cars.empty?\n+      puts 'There is no car in the train. You should create it'\n+      return\n+    end\n+    print_collection(train.cars, 'Available cars')\n+    car = select_item(train.cars, 'Select car:')\n+    train.remove_car(car)\n+    print_collection(train.cars, \"#{train.cars.size} cars on the #{train.to_s} train\")\n+  end\n+\n+  def move_train_forward\n+    header('Move Train Forward')\n+    if @routes.empty?\n+      puts 'There is no route. You should create it'\n+      return\n+    end\n+    if @trains.empty?\n+      puts 'There is no train. You should create it'\n+      return\n+\n+    end\n+    print_collection(@trains, 'Available trains')\n+    train = select_item(@trains, 'Select train:')\n+\n+    if train.route.nil?\n+      puts 'Train does not belong to any route'\n+      puts\n+      return\n+    end\n+\n+    train.move_forward\n+\n+    if train.prev_station.name == train.current_station.name","path":"lesson_03/lib/runner.rb","position":225,"original_position":225,"commit_id":"5d520df2140fffc16d9998d154cd3daa0bfd94d6","original_commit_id":"5d520df2140fffc16d9998d154cd3daa0bfd94d6","user":{"login":"iBublik","id":11278497,"avatar_url":"https://avatars1.githubusercontent.com/u/11278497?v=4","gravatar_id":"","url":"https://api.github.com/users/iBublik","html_url":"https://github.com/iBublik","followers_url":"https://api.github.com/users/iBublik/followers","following_url":"https://api.github.com/users/iBublik/following{/other_user}","gists_url":"https://api.github.com/users/iBublik/gists{/gist_id}","starred_url":"https://api.github.com/users/iBublik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iBublik/subscriptions","organizations_url":"https://api.github.com/users/iBublik/orgs","repos_url":"https://api.github.com/users/iBublik/repos","events_url":"https://api.github.com/users/iBublik/events{/privacy}","received_events_url":"https://api.github.com/users/iBublik/received_events","type":"User","site_admin":false},"body":"Это условие выполнится только если у предыдущей станции имя совпадает с текущей. Это вовсе не означает, что поезд не сдвинулся с места. Тебе надо опираться на результат метода `move_forward` (он вернет nil, если поезд не двигался)","created_at":"2018-02-02T07:19:50Z","updated_at":"2018-02-02T07:21:17Z","html_url":"https://github.com/olgkv/just_ruby/pull/2#discussion_r165572624","pull_request_url":"https://api.github.com/repos/olgkv/just_ruby/pulls/2","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/olgkv/just_ruby/pulls/comments/165572624"},"html":{"href":"https://github.com/olgkv/just_ruby/pull/2#discussion_r165572624"},"pull_request":{"href":"https://api.github.com/repos/olgkv/just_ruby/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/olgkv/just_ruby/pulls/2","id":166281527,"html_url":"https://github.com/olgkv/just_ruby/pull/2","diff_url":"https://github.com/olgkv/just_ruby/pull/2.diff","patch_url":"https://github.com/olgkv/just_ruby/pull/2.patch","issue_url":"https://api.github.com/repos/olgkv/just_ruby/issues/2","number":2,"state":"open","locked":false,"title":"Module4","user":{"login":"olgkv","id":12646768,"avatar_url":"https://avatars0.githubusercontent.com/u/12646768?v=4","gravatar_id":"","url":"https://api.github.com/users/olgkv","html_url":"https://github.com/olgkv","followers_url":"https://api.github.com/users/olgkv/followers","following_url":"https://api.github.com/users/olgkv/following{/other_user}","gists_url":"https://api.github.com/users/olgkv/gists{/gist_id}","starred_url":"https://api.github.com/users/olgkv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/olgkv/subscriptions","organizations_url":"https://api.github.com/users/olgkv/orgs","repos_url":"https://api.github.com/users/olgkv/repos","events_url":"https://api.github.com/users/olgkv/events{/privacy}","received_events_url":"https://api.github.com/users/olgkv/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-01-31T14:54:27Z","updated_at":"2018-02-02T07:21:17Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f573455244613b258978044a59d9ae70d61e2977","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"milestone":null,"commits_url":"https://api.github.com/repos/olgkv/just_ruby/pulls/2/commits","review_comments_url":"https://api.github.com/repos/olgkv/just_ruby/pulls/2/comments","review_comment_url":"https://api.github.com/repos/olgkv/just_ruby/pulls/comments{/number}","comments_url":"https://api.github.com/repos/olgkv/just_ruby/issues/2/comments","statuses_url":"https://api.github.com/repos/olgkv/just_ruby/statuses/5d520df2140fffc16d9998d154cd3daa0bfd94d6","head":{"label":"olgkv:module4","ref":"module4","sha":"5d520df2140fffc16d9998d154cd3daa0bfd94d6","user":{"login":"olgkv","id":12646768,"avatar_url":"https://avatars0.githubusercontent.com/u/12646768?v=4","gravatar_id":"","url":"https://api.github.com/users/olgkv","html_url":"https://github.com/olgkv","followers_url":"https://api.github.com/users/olgkv/followers","following_url":"https://api.github.com/users/olgkv/following{/other_user}","gists_url":"https://api.github.com/users/olgkv/gists{/gist_id}","starred_url":"https://api.github.com/users/olgkv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/olgkv/subscriptions","organizations_url":"https://api.github.com/users/olgkv/orgs","repos_url":"https://api.github.com/users/olgkv/repos","events_url":"https://api.github.com/users/olgkv/events{/privacy}","received_events_url":"https://api.github.com/users/olgkv/received_events","type":"User","site_admin":false},"repo":{"id":118556704,"name":"just_ruby","full_name":"olgkv/just_ruby","owner":{"login":"olgkv","id":12646768,"avatar_url":"https://avatars0.githubusercontent.com/u/12646768?v=4","gravatar_id":"","url":"https://api.github.com/users/olgkv","html_url":"https://github.com/olgkv","followers_url":"https://api.github.com/users/olgkv/followers","following_url":"https://api.github.com/users/olgkv/following{/other_user}","gists_url":"https://api.github.com/users/olgkv/gists{/gist_id}","starred_url":"https://api.github.com/users/olgkv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/olgkv/subscriptions","organizations_url":"https://api.github.com/users/olgkv/orgs","repos_url":"https://api.github.com/users/olgkv/repos","events_url":"https://api.github.com/users/olgkv/events{/privacy}","received_events_url":"https://api.github.com/users/olgkv/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/olgkv/just_ruby","description":null,"fork":false,"url":"https://api.github.com/repos/olgkv/just_ruby","forks_url":"https://api.github.com/repos/olgkv/just_ruby/forks","keys_url":"https://api.github.com/repos/olgkv/just_ruby/keys{/key_id}","collaborators_url":"https://api.github.com/repos/olgkv/just_ruby/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/olgkv/just_ruby/teams","hooks_url":"https://api.github.com/repos/olgkv/just_ruby/hooks","issue_events_url":"https://api.github.com/repos/olgkv/just_ruby/issues/events{/number}","events_url":"https://api.github.com/repos/olgkv/just_ruby/events","assignees_url":"https://api.github.com/repos/olgkv/just_ruby/assignees{/user}","branches_url":"https://api.github.com/repos/olgkv/just_ruby/branches{/branch}","tags_url":"https://api.github.com/repos/olgkv/just_ruby/tags","blobs_url":"https://api.github.com/repos/olgkv/just_ruby/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/olgkv/just_ruby/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/olgkv/just_ruby/git/refs{/sha}","trees_url":"https://api.github.com/repos/olgkv/just_ruby/git/trees{/sha}","statuses_url":"https://api.github.com/repos/olgkv/just_ruby/statuses/{sha}","languages_url":"https://api.github.com/repos/olgkv/just_ruby/languages","stargazers_url":"https://api.github.com/repos/olgkv/just_ruby/stargazers","contributors_url":"https://api.github.com/repos/olgkv/just_ruby/contributors","subscribers_url":"https://api.github.com/repos/olgkv/just_ruby/subscribers","subscription_url":"https://api.github.com/repos/olgkv/just_ruby/subscription","commits_url":"https://api.github.com/repos/olgkv/just_ruby/commits{/sha}","git_commits_url":"https://api.github.com/repos/olgkv/just_ruby/git/commits{/sha}","comments_url":"https://api.github.com/repos/olgkv/just_ruby/comments{/number}","issue_comment_url":"https://api.github.com/repos/olgkv/just_ruby/issues/comments{/number}","contents_url":"https://api.github.com/repos/olgkv/just_ruby/contents/{+path}","compare_url":"https://api.github.com/repos/olgkv/just_ruby/compare/{base}...{head}","merges_url":"https://api.github.com/repos/olgkv/just_ruby/merges","archive_url":"https://api.github.com/repos/olgkv/just_ruby/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/olgkv/just_ruby/downloads","issues_url":"https://api.github.com/repos/olgkv/just_ruby/issues{/number}","pulls_url":"https://api.github.com/repos/olgkv/just_ruby/pulls{/number}","milestones_url":"https://api.github.com/repos/olgkv/just_ruby/milestones{/number}","notifications_url":"https://api.github.com/repos/olgkv/just_ruby/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/olgkv/just_ruby/labels{/name}","releases_url":"https://api.github.com/repos/olgkv/just_ruby/releases{/id}","deployments_url":"https://api.github.com/repos/olgkv/just_ruby/deployments","created_at":"2018-01-23T04:16:04Z","updated_at":"2018-01-23T04:16:41Z","pushed_at":"2018-02-01T18:32:39Z","git_url":"git://github.com/olgkv/just_ruby.git","ssh_url":"git@github.com:olgkv/just_ruby.git","clone_url":"https://github.com/olgkv/just_ruby.git","svn_url":"https://github.com/olgkv/just_ruby","homepage":null,"size":44,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"olgkv:master","ref":"master","sha":"fbc23f3c0ae4829829dbc4de0f58e04fb47a8499","user":{"login":"olgkv","id":12646768,"avatar_url":"https://avatars0.githubusercontent.com/u/12646768?v=4","gravatar_id":"","url":"https://api.github.com/users/olgkv","html_url":"https://github.com/olgkv","followers_url":"https://api.github.com/users/olgkv/followers","following_url":"https://api.github.com/users/olgkv/following{/other_user}","gists_url":"https://api.github.com/users/olgkv/gists{/gist_id}","starred_url":"https://api.github.com/users/olgkv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/olgkv/subscriptions","organizations_url":"https://api.github.com/users/olgkv/orgs","repos_url":"https://api.github.com/users/olgkv/repos","events_url":"https://api.github.com/users/olgkv/events{/privacy}","received_events_url":"https://api.github.com/users/olgkv/received_events","type":"User","site_admin":false},"repo":{"id":118556704,"name":"just_ruby","full_name":"olgkv/just_ruby","owner":{"login":"olgkv","id":12646768,"avatar_url":"https://avatars0.githubusercontent.com/u/12646768?v=4","gravatar_id":"","url":"https://api.github.com/users/olgkv","html_url":"https://github.com/olgkv","followers_url":"https://api.github.com/users/olgkv/followers","following_url":"https://api.github.com/users/olgkv/following{/other_user}","gists_url":"https://api.github.com/users/olgkv/gists{/gist_id}","starred_url":"https://api.github.com/users/olgkv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/olgkv/subscriptions","organizations_url":"https://api.github.com/users/olgkv/orgs","repos_url":"https://api.github.com/users/olgkv/repos","events_url":"https://api.github.com/users/olgkv/events{/privacy}","received_events_url":"https://api.github.com/users/olgkv/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/olgkv/just_ruby","description":null,"fork":false,"url":"https://api.github.com/repos/olgkv/just_ruby","forks_url":"https://api.github.com/repos/olgkv/just_ruby/forks","keys_url":"https://api.github.com/repos/olgkv/just_ruby/keys{/key_id}","collaborators_url":"https://api.github.com/repos/olgkv/just_ruby/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/olgkv/just_ruby/teams","hooks_url":"https://api.github.com/repos/olgkv/just_ruby/hooks","issue_events_url":"https://api.github.com/repos/olgkv/just_ruby/issues/events{/number}","events_url":"https://api.github.com/repos/olgkv/just_ruby/events","assignees_url":"https://api.github.com/repos/olgkv/just_ruby/assignees{/user}","branches_url":"https://api.github.com/repos/olgkv/just_ruby/branches{/branch}","tags_url":"https://api.github.com/repos/olgkv/just_ruby/tags","blobs_url":"https://api.github.com/repos/olgkv/just_ruby/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/olgkv/just_ruby/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/olgkv/just_ruby/git/refs{/sha}","trees_url":"https://api.github.com/repos/olgkv/just_ruby/git/trees{/sha}","statuses_url":"https://api.github.com/repos/olgkv/just_ruby/statuses/{sha}","languages_url":"https://api.github.com/repos/olgkv/just_ruby/languages","stargazers_url":"https://api.github.com/repos/olgkv/just_ruby/stargazers","contributors_url":"https://api.github.com/repos/olgkv/just_ruby/contributors","subscribers_url":"https://api.github.com/repos/olgkv/just_ruby/subscribers","subscription_url":"https://api.github.com/repos/olgkv/just_ruby/subscription","commits_url":"https://api.github.com/repos/olgkv/just_ruby/commits{/sha}","git_commits_url":"https://api.github.com/repos/olgkv/just_ruby/git/commits{/sha}","comments_url":"https://api.github.com/repos/olgkv/just_ruby/comments{/number}","issue_comment_url":"https://api.github.com/repos/olgkv/just_ruby/issues/comments{/number}","contents_url":"https://api.github.com/repos/olgkv/just_ruby/contents/{+path}","compare_url":"https://api.github.com/repos/olgkv/just_ruby/compare/{base}...{head}","merges_url":"https://api.github.com/repos/olgkv/just_ruby/merges","archive_url":"https://api.github.com/repos/olgkv/just_ruby/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/olgkv/just_ruby/downloads","issues_url":"https://api.github.com/repos/olgkv/just_ruby/issues{/number}","pulls_url":"https://api.github.com/repos/olgkv/just_ruby/pulls{/number}","milestones_url":"https://api.github.com/repos/olgkv/just_ruby/milestones{/number}","notifications_url":"https://api.github.com/repos/olgkv/just_ruby/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/olgkv/just_ruby/labels{/name}","releases_url":"https://api.github.com/repos/olgkv/just_ruby/releases{/id}","deployments_url":"https://api.github.com/repos/olgkv/just_ruby/deployments","created_at":"2018-01-23T04:16:04Z","updated_at":"2018-01-23T04:16:41Z","pushed_at":"2018-02-01T18:32:39Z","git_url":"git://github.com/olgkv/just_ruby.git","ssh_url":"git@github.com:olgkv/just_ruby.git","clone_url":"https://github.com/olgkv/just_ruby.git","svn_url":"https://github.com/olgkv/just_ruby","homepage":null,"size":44,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/olgkv/just_ruby/pulls/2"},"html":{"href":"https://github.com/olgkv/just_ruby/pull/2"},"issue":{"href":"https://api.github.com/repos/olgkv/just_ruby/issues/2"},"comments":{"href":"https://api.github.com/repos/olgkv/just_ruby/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/olgkv/just_ruby/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/olgkv/just_ruby/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/olgkv/just_ruby/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/olgkv/just_ruby/statuses/5d520df2140fffc16d9998d154cd3daa0bfd94d6"}},"author_association":"OWNER"}}
{"actor":{"display_login":"iBublik"}}