class WWFinder::CLI

Attributes

input[RW]
selected_city[RW]
selected_continent[RW]
selected_country[RW]

Public Instance Methods

app_loop() click to toggle source
# File lib/ww_finder/cli.rb, line 10
def app_loop 
    while @input != "exit"
        print_countries_list
    end
end
error(entry_point) click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/ww_finder/cli.rb, line 82
def instructions 
    puts "\nEnter the option number to see more details".green
end
print_buildings_list() click to toggle source
print_cities_list() click to toggle source
print_countries_list() click to toggle source
resize_screen() click to toggle source
# File lib/ww_finder/cli.rb, line 16
def resize_screen
    print "\e[8;50;150t"
end
run() click to toggle source
# File lib/ww_finder/cli.rb, line 4
def run 
    welcome
    app_loop
    start
end
set_city() click to toggle source
# 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() click to toggle source
# File lib/ww_finder/cli.rb, line 47
def set_continent
    @selected_continent = WWFinder::Continent.find(user_num_input)
end
set_country() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/ww_finder/cli.rb, line 138
def user_num_input
    input.to_i - 1 
end
valid_input(data) click to toggle source
# File lib/ww_finder/cli.rb, line 101
def valid_input(data)
    user_num_input >= 0 && user_num_input <= data.length - 1
end
welcome() click to toggle source
# 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() click to toggle source
# 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