Class: NytJourneys::CommandLineInterface
- Inherits:
-
Object
- Object
- NytJourneys::CommandLineInterface
- Defined in:
- lib/nyt_journeys/command_line_interface.rb
Instance Method Summary collapse
- #call ⇒ Object
- #greeting ⇒ Object
- #list_journeys ⇒ Object
- #list_types ⇒ Object
- #navigate_category(category) ⇒ Object
- #navigate_journeys ⇒ Object
- #navigate_types ⇒ Object
- #print_category(category) ⇒ Object
- #print_journey(journey) ⇒ Object
- #start ⇒ Object
Instance Method Details
#call ⇒ Object
2 3 4 5 |
# File 'lib/nyt_journeys/command_line_interface.rb', line 2 def call NytJourneys::Data_Generator.new.make_journeys start end |
#greeting ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/nyt_journeys/command_line_interface.rb', line 7 def greeting puts "" puts "~~*~~*~~*~~ New York Times Journeys ~~*~~*~~*~~" puts "" puts NytJourneys::Scraper.scrape_quotes.sample puts "" end |
#list_journeys ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/nyt_journeys/command_line_interface.rb', line 15 def list_journeys puts "" puts "~~*~~*~~*~~ Available New York Times Journeys ~~*~~*~~*~~" puts "" NytJourneys::Journeys.all.each.with_index(1) do |journey, index| puts "#{index}. #{journey.name}" end puts "" end |
#list_types ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/nyt_journeys/command_line_interface.rb', line 61 def list_types puts "" puts "~~*~~*~~*~~ Journeys Focused On ~~*~~*~~*~~" puts "" NytJourneys::Journeys.types.each.with_index(1) do |type, index| puts "#{index}. #{type}" end puts "" end |
#navigate_category(category) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/nyt_journeys/command_line_interface.rb', line 99 def navigate_category(category) puts "" puts "Which journey would you like to learn more about? Enter 1 - #{NytJourneys::Journeys.find_by_type(category).count}." puts "" puts "Enter 'list' to see all journeys." puts "Enter 'types' to see journey categories." puts "Enter 'exit' to end the program." input = gets.downcase.strip if input == "list" navigate_journeys elsif input == "types" navigate_types elsif input.to_i > 0 if journey = NytJourneys::Journeys.find_by_type(category)[input.to_i - 1] print_journey(journey) end end end |
#navigate_journeys ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/nyt_journeys/command_line_interface.rb', line 25 def navigate_journeys list_journeys puts "" puts "Which journey would you like to learn more about? Enter 1 - #{NytJourneys::Journeys.all.count}." puts "" puts "Enter 'types' to see journey categories." puts "Enter 'exit' to end the program." input = gets.downcase.strip if input == "types" navigate_types elsif input.to_i > 0 if journey = NytJourneys::Journeys.find(input.to_i) print_journey(journey) end end end |
#navigate_types ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/nyt_journeys/command_line_interface.rb', line 71 def navigate_types list_types puts "" puts "Which type of journey would you like to take? Enter 1 - #{NytJourneys::Journeys.types.count}." puts "" puts "Enter 'list' to see all journeys." puts "Enter 'exit' to end the program." input = gets.downcase.strip if input == "list" navigate_journeys elsif input.to_i > 0 if category = NytJourneys::Journeys.types[input.to_i - 1] print_category(category) navigate_category(category) end end end |
#print_category(category) ⇒ Object
89 90 91 92 93 94 95 96 97 |
# File 'lib/nyt_journeys/command_line_interface.rb', line 89 def print_category(category) puts "" puts "~~*~~*~~*~~ Journeys Focused On #{category} ~~*~~*~~*~~" puts "" NytJourneys::Journeys.find_by_type(category).each.with_index(1) do |journey, index| puts "#{index}. #{journey.name}" end puts "" end |
#print_journey(journey) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/nyt_journeys/command_line_interface.rb', line 42 def print_journey(journey) puts "" puts "~~*~~*~~*~~ #{journey.name} ~~*~~*~~*~~" puts "A Journey Focused On #{journey.type}" puts "" puts journey.description puts "" puts "From: #{journey.cost}" puts "" puts "Journey Duration: #{journey.length}" puts "" puts "Available Dates:" puts journey.dates puts "" puts "Itinerary:" puts journey.itinerary puts "" end |
#start ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/nyt_journeys/command_line_interface.rb', line 118 def start greeting input = nil while input != "exit" puts "" puts "Enter 'list' to see all journeys." puts "Enter 'types' to see journey categories." puts "Enter 'exit' to end the program." puts "" input = gets.downcase.strip if input == "list" navigate_journeys elsif input == "types" navigate_types end end puts "" puts NytJourneys::Scraper.scrape_quotes.sample puts "" puts "Enjoy the journey!" end |