Class: WWFinder::CLI
- Inherits:
-
Object
- Object
- WWFinder::CLI
- Defined in:
- lib/ww_finder/cli.rb
Instance Attribute Summary collapse
-
#input ⇒ Object
Returns the value of attribute input.
-
#selected_city ⇒ Object
Returns the value of attribute selected_city.
-
#selected_continent ⇒ Object
Returns the value of attribute selected_continent.
-
#selected_country ⇒ Object
Returns the value of attribute selected_country.
Instance Method Summary collapse
- #app_loop ⇒ Object
- #error(entry_point) ⇒ Object
- #get_building_selection ⇒ Object
- #get_city_selection ⇒ Object
- #get_country_selection ⇒ Object
- #get_user_selection ⇒ Object
- #goodbye ⇒ Object
- #instructions ⇒ Object
- #print_buildings_list ⇒ Object
- #print_cities_list ⇒ Object
- #print_countries_list ⇒ Object
- #resize_screen ⇒ Object
- #run ⇒ Object
- #set_city ⇒ Object
- #set_continent ⇒ Object
- #set_country ⇒ Object
- #show_building ⇒ Object
- #user_num_input ⇒ Object
- #valid_input(data) ⇒ Object
- #welcome ⇒ Object
- #what_next ⇒ Object
Instance Attribute Details
#input ⇒ Object
Returns the value of attribute input.
2 3 4 |
# File 'lib/ww_finder/cli.rb', line 2 def input @input end |
#selected_city ⇒ Object
Returns the value of attribute selected_city.
2 3 4 |
# File 'lib/ww_finder/cli.rb', line 2 def selected_city @selected_city end |
#selected_continent ⇒ Object
Returns the value of attribute selected_continent.
2 3 4 |
# File 'lib/ww_finder/cli.rb', line 2 def selected_continent @selected_continent end |
#selected_country ⇒ Object
Returns the value of attribute selected_country.
2 3 4 |
# File 'lib/ww_finder/cli.rb', line 2 def selected_country @selected_country end |
Instance Method Details
#app_loop ⇒ Object
10 11 12 13 14 |
# File 'lib/ww_finder/cli.rb', line 10 def app_loop while @input != "exit" print_countries_list end end |
#error(entry_point) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/ww_finder/cli.rb', line 105 def error(entry_point) exit if input == "exit" puts "\nOops, that's not a valid #{entry_point} option".light_white.on_red.bold case entry_point when "continent" get_country_selection when "country" get_country_selection when "city" get_city_selection when "building" get_building_selection end end |
#get_building_selection ⇒ Object
86 87 88 89 90 |
# File 'lib/ww_finder/cli.rb', line 86 def get_building_selection instructions get_user_selection valid_input(selected_city.buildings) ? show_building : error("building") end |
#get_city_selection ⇒ Object
63 64 65 66 67 |
# File 'lib/ww_finder/cli.rb', line 63 def get_city_selection instructions get_user_selection valid_input(selected_country.cities) ? set_city : error("city") end |
#get_country_selection ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/ww_finder/cli.rb', line 37 def get_country_selection puts "Enter a continent number and country number eg '3, 2'".light_white.on_green get_user_selection cc_input = input.split(',') @input = cc_input[0] valid_input(WWFinder::Continent.all) ? set_continent : error("continent") @input = cc_input[1] valid_input(selected_continent.countries) ? set_country : error("country") end |
#get_user_selection ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/ww_finder/cli.rb', line 125 def get_user_selection @input = gets.strip case @input when "cities" print_cities_list when "back" print_buildings_list when "exit" goodbye exit end end |
#goodbye ⇒ Object
142 143 144 145 |
# File 'lib/ww_finder/cli.rb', line 142 def goodbye puts "\nHappy working! Don't forget to take a break!\n".light_white.on_magenta.bold exit end |
#instructions ⇒ Object
82 83 84 |
# File 'lib/ww_finder/cli.rb', line 82 def instructions puts "\nEnter the option number to see more details".green end |
#print_buildings_list ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/ww_finder/cli.rb', line 74 def print_buildings_list @selected_city.get_buildings @selected_city.buildings.each.with_index(1) do | building, idx | puts "#{idx}: #{building.address}" end get_building_selection end |
#print_cities_list ⇒ Object
56 57 58 59 60 61 |
# File 'lib/ww_finder/cli.rb', line 56 def print_cities_list selected_country.cities.each.with_index(1) do | city, idx | puts "#{idx}: #{city.name}" end get_city_selection end |
#print_countries_list ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ww_finder/cli.rb', line 26 def print_countries_list resize_screen table_data = [] WWFinder::Continent.all.each.with_index(1) do | cont, i | table_data << {"#{i.to_s.light_white.bold}. #{cont.name.light_white.on_magenta}": WWFinder::Continent.all.map{| cont | cont.countries[i - 1] ? "#{i.to_s.magenta}: #{cont.countries[i - 1].name}" : nil }} end table = TTY::Table.new(table_data) puts table.render(:ascii) get_country_selection end |
#resize_screen ⇒ Object
16 17 18 |
# File 'lib/ww_finder/cli.rb', line 16 def resize_screen print "\e[8;50;150t" end |
#run ⇒ Object
4 5 6 7 8 |
# File 'lib/ww_finder/cli.rb', line 4 def run welcome app_loop start end |
#set_city ⇒ Object
69 70 71 72 |
# File 'lib/ww_finder/cli.rb', line 69 def set_city @selected_city = selected_country.find_city(user_num_input) print_buildings_list end |
#set_continent ⇒ Object
47 48 49 |
# File 'lib/ww_finder/cli.rb', line 47 def set_continent @selected_continent = WWFinder::Continent.find(user_num_input) end |
#set_country ⇒ Object
51 52 53 54 |
# File 'lib/ww_finder/cli.rb', line 51 def set_country @selected_country = selected_continent.find_country(user_num_input) print_cities_list end |
#show_building ⇒ Object
92 93 94 95 96 97 98 99 |
# File 'lib/ww_finder/cli.rb', line 92 def show_building building = @selected_city.buildings[user_num_input] building.prepare_details puts "\n#{building.name}".light_white.on_magenta.bold puts building.info puts building.address.light_white.on_light_magenta what_next end |
#user_num_input ⇒ Object
138 139 140 |
# File 'lib/ww_finder/cli.rb', line 138 def user_num_input input.to_i - 1 end |
#valid_input(data) ⇒ Object
101 102 103 |
# File 'lib/ww_finder/cli.rb', line 101 def valid_input(data) user_num_input >= 0 && user_num_input <= data.length - 1 end |
#welcome ⇒ Object
20 21 22 23 24 |
# File 'lib/ww_finder/cli.rb', line 20 def welcome puts "\nHai there! Are you looking for a place to work today?".light_white.on_magenta.bold puts "Hit enter to continue".green get_user_selection end |
#what_next ⇒ Object
120 121 122 123 |
# File 'lib/ww_finder/cli.rb', line 120 def what_next puts "\nIf you are done, type 'exit', otherwise type 'back' to see other buildings in this city, 'cities' to see other cities in this country, or hit enter to see more countries".green get_user_selection end |