Class: WorldTraveler::CLI
- Inherits:
-
Object
- Object
- WorldTraveler::CLI
- Defined in:
- lib/world_traveler/cli.rb
Instance Method Summary collapse
- #call ⇒ Object
- #get_continents ⇒ Object
- #get_user_choice ⇒ Object
- #get_user_highlight(cont) ⇒ Object
- #goodbye ⇒ Object
- #list_continents ⇒ Object
- #next_action ⇒ Object
- #show_highlight_details(highlight) ⇒ Object
- #show_highlights_for(chosen_continent) ⇒ Object
Instance Method Details
#call ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/world_traveler/cli.rb', line 3 def call system("clear") WorldTraveler::Display. sleep(4) @input = "" while @input != "exit" get_continents list_continents get_user_choice next_action end goodbye end |
#get_continents ⇒ Object
19 20 21 |
# File 'lib/world_traveler/cli.rb', line 19 def get_continents @continent = WorldTraveler::Continents.all end |
#get_user_choice ⇒ Object
35 36 37 38 |
# File 'lib/world_traveler/cli.rb', line 35 def get_user_choice chosen_continent = gets.strip.to_i show_highlights_for(chosen_continent) end |
#get_user_highlight(cont) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/world_traveler/cli.rb', line 55 def get_user_highlight(cont) puts "\nChoose a highlight in #{cont.name} to see more details.".light_blue.bold input = (gets.strip.to_i)-1 if input.between?(0,cont.highlights.size-1) highlight = cont.highlights[input] highlight.index = input.to_i - 1 highlight.get_highlight_details show_highlight_details(highlight) else puts "Not sure what you mean. You must enter a number between 1 - #{cont.highlights.size}." end end |
#goodbye ⇒ Object
79 80 81 82 |
# File 'lib/world_traveler/cli.rb', line 79 def goodbye system("clear") WorldTraveler::Display.goodbye end |
#list_continents ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/world_traveler/cli.rb', line 23 def list_continents system("clear") WorldTraveler::Display.continent_list @continent.each.with_index(1) do |continent, index| puts "#{index}. #{continent.name}".center(135).rjust(10) puts "-----------------------------------------".green.center(150) end puts "" puts "Where would you like to go? (Choose 1-#{@continent.size})".center(135).green.bold end |
#next_action ⇒ Object
74 75 76 77 |
# File 'lib/world_traveler/cli.rb', line 74 def next_action puts "\nType 'exit' to exit or any key to return to main menu.".green.bold @input = gets.strip end |
#show_highlight_details(highlight) ⇒ Object
68 69 70 71 72 |
# File 'lib/world_traveler/cli.rb', line 68 def show_highlight_details(highlight) puts "---------------------------------#{highlight.name}---------------------------------".center(155).yellow.bold highlight.info.each {|i| puts "#{i}\n"} puts "-----------------------------------------------------------------------------------".center(155).yellow.bold end |
#show_highlights_for(chosen_continent) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/world_traveler/cli.rb', line 40 def show_highlights_for(chosen_continent) system("clear") if chosen_continent.between?(1,@continent.size) cont = @continent[chosen_continent - 1] cont.get_highlights puts "Here are highlights for #{cont.name}".light_blue.bold cont.highlights.each.with_index(1) do |high, idx| puts "#{idx}. #{high.name}" end get_user_highlight(cont) else puts "Not sure what you mean. You must enter a number between 1 - #{@continent.size}." end end |