Class: TrailInfo::CLI
- Inherits:
-
Object
- Object
- TrailInfo::CLI
- Defined in:
- lib/trail_info/CLI.rb
Constant Summary collapse
- @@STATE_NAMES =
{AL: 'ALABAMA', AK: 'ALASKA','AZ'=>'ARIZONA','AR'=>'ARKANSAS','CA'=>'CALIFORNIA','CO'=>'COLORADO','CT'=>'CONNECTICUT', 'DE'=>'DELAWARE','DC'=>'DISTRICT OF COLUMBIA','FL'=>'FLORIDA','GA'=>'GEORGIA','HI'=>'HAWAII','ID'=>'IDAHO', 'IL'=>'ILLINOIS','IN'=>'INDIANA','IA'=>'IOWA', 'KS'=>'KANSAS', 'KY'=>'KENTUCKY', 'LA'=>'LOUISIANA', 'ME'=>'MAINE', 'MD'=>'MARYLAND', 'MA'=>'MASSACHUSETTS', 'MI'=>'MICHIGAN', 'MN'=>'MINNESOTA', 'MS'=>'MISSISSIPPI', 'MO'=>'MISSOURI', 'MT'=>'MONTANA', 'NE'=>'NEBRASKA', 'NV'=>'NEVADA', 'NH'=>'NEW HAMPSHIRE', 'NJ'=>'NEW JERSEY', 'NM'=>'NEW MEXICO', 'NY'=>'NEW YORK', 'NC'=>'NORTH CAROLINA', 'ND'=>'NORTH DAKOTA', 'OH'=>'OHIO', 'OK'=>'OKLAHOMA', 'OR'=>'OREGON', 'PA'=>'PENNSYLVANIA', 'RI'=>'RHODE ISLAND', 'SC'=>'SOUTH CAROLINA', 'SD'=>'SOUTH DAKOTA', 'TN'=>'TENNESSEE', 'TX'=>'TEXAS', 'UT'=>'UTAH', 'VT'=>'VERMONT', 'VA'=>'VIRGINIA', 'WA'=>'WASHINGTON', 'WV'=>'WEST VIRGINIA', 'WI'=>'WISCONSIN', 'WY'=>'WYOMING'}
Instance Method Summary collapse
- #call ⇒ Object
-
#exit_input ⇒ Object
takes user input and displays trail description, returns user to previous menus, or exits.
-
#initiate_state(state_number) ⇒ Object
creates new state instance.
-
#initiate_trails_report(state_number) ⇒ Object
Writes state selection, initiates new state instance, lists states trails.
- #list_states ⇒ Object
-
#list_trails(state_number) ⇒ Object
checks input to determine whether to list trails or exit.
-
#list_trails_report ⇒ Object
populates trail list for selected state and asks for input for more details, reset, or exit.
- #menu ⇒ Object
-
#state_input ⇒ Object
allows user to select which state to view trails in.
-
#trail_description(trail_array, trail_number) ⇒ Object
Writes detailed trail information and asks for user input.
Instance Method Details
#call ⇒ Object
14 15 16 17 |
# File 'lib/trail_info/CLI.rb', line 14 def call puts "Welcome to Trail Finder!" end |
#exit_input ⇒ Object
takes user input and displays trail description, returns user to previous menus, or exits
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/trail_info/CLI.rb', line 64 def exit_input #takes user input and displays trail description, returns user to previous menus, or exits @trail_array = TrailInfo::State.all max_trail_number = @trail_array[0].trails.length input = gets.strip.downcase @trail_number = input.to_i if input.to_i.between?(1, max_trail_number) trail_description(@trail_array, @trail_number) else if input == 'back' ? list_trails_report : if input == "reset" ? TrailInfo::State.clear_all && call : (input == "exit" ? exit : (puts "I'm sorry, I don't understand. Please try again." && exit_input)) end end end end |
#initiate_state(state_number) ⇒ Object
creates new state instance
54 55 56 |
# File 'lib/trail_info/CLI.rb', line 54 def initiate_state(state_number) #creates new state instance TrailInfo::State.new(@@STATE_NAMES.values[state_number - 1], @@STATE_NAMES.keys[state_number - 1]) end |
#initiate_trails_report(state_number) ⇒ Object
Writes state selection, initiates new state instance, lists states trails
48 49 50 51 52 |
# File 'lib/trail_info/CLI.rb', line 48 def initiate_trails_report(state_number) #Writes state selection, initiates new state instance, lists states trails puts "You've selected #{state_number}. #{@@STATE_NAMES.values[state_number - 1]}. Here are the available trails in #{@@STATE_NAMES[state_number]} according to TrailLink.com. This may take a moment to load.\n \n" initiate_state(state_number) list_trails_report end |
#list_states ⇒ Object
24 25 26 27 28 29 |
# File 'lib/trail_info/CLI.rb', line 24 def list_states @@STATE_NAMES.each.with_index(1) do |state_name, index| puts "#{index}. #{state_name[1]}" end state_input end |
#list_trails(state_number) ⇒ Object
checks input to determine whether to list trails or exit
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/trail_info/CLI.rb', line 36 def list_trails(state_number) #checks input to determine whether to list trails or exit if state_number.to_i.between?(1, 51) initiate_trails_report(state_number.to_i) elsif state_number == "exit" exit else puts "Please enter a valid number between 1 - 51." state_input end end |
#list_trails_report ⇒ Object
populates trail list for selected state and asks for input for more details, reset, or exit
58 59 60 61 62 |
# File 'lib/trail_info/CLI.rb', line 58 def list_trails_report #populates trail list for selected state and asks for input for more details, reset, or exit TrailInfo::State.trail_list puts "\nPlease select a trail number to see more details, enter 'reset' to go back to the main menu, or 'exit' to exit the program." exit_input end |
#menu ⇒ Object
19 20 21 22 |
# File 'lib/trail_info/CLI.rb', line 19 def puts "Enter which state number you'd like to find a trail in and press enter or type 'exit' to exit the program.\n\n" list_states end |
#state_input ⇒ Object
allows user to select which state to view trails in
31 32 33 34 |
# File 'lib/trail_info/CLI.rb', line 31 def state_input #allows user to select which state to view trails in selection = gets.strip.downcase list_trails(selection) end |
#trail_description(trail_array, trail_number) ⇒ Object
Writes detailed trail information and asks for user input
78 79 80 81 82 83 84 85 |
# File 'lib/trail_info/CLI.rb', line 78 def trail_description(trail_array, trail_number) #Writes detailed trail information and asks for user input trail = trail_array[0].trails[trail_number] puts "#{trail.name} | Length: #{trail.length} | Surface: #{trail.surface}|" puts "#{trail.synopsis}" puts "\nFor more information visit: #{trail.url}" puts "\nEnter 'back' to return to the list of trails, 'reset' to go back to the main menu, or 'exit' to exit the program." exit_input end |