class WashingtonHikes::CLI
Attributes
region[RW]
Public Instance Methods
choose_hike()
click to toggle source
Prompts users to choose a hike from a list of hikes
# File lib/washington_hikes/cli.rb, line 71 def choose_hike # Gather list of hikes - either all hikes, or hikes in a specific region if @region == "all" puts "\n\nHere are the most popular hikes in Washington:\n " hikes = WashingtonHikes::Hike.all else puts "\n\nHere are the most popular hikes in the #{@region.name}:\n " hikes = @region.hikes end # Lists hikes in designated region list_hikes(hikes) puts "\nChoose a hike by typing the corresponding number, or type 'menu' to go to the main menu." input = gets.chomp if input == "menu" # Returns user to main menu welcome elsif input.to_i.between?(1, hikes.size) # ID user-selected hike and show them hike details list_hike_details(hikes[input.to_i - 1]) @region = hikes[input.to_i - 1].region else # If input isn't recognized, have user choose hike again choose_hike end what_next? # Prompt user to take another action after seeing hike details end
choose_region()
click to toggle source
Prompts user to choose a region from a list of regions
# File lib/washington_hikes/cli.rb, line 39 def choose_region puts "\n\nHere are the regions you can choose from:\n " regions = WashingtonHikes::Region.all # Get list of regions list_regions(regions) # Display list of regions puts "\nChoose a region by typing the corresponding number, or type 'menu' to go to the main menu." input = gets.chomp if input == "menu" # Returns user to main menu welcome elsif input.to_i.between?(1, regions.size) # ID user-selected region and lets them choose a hike @region = regions[input.to_i - 1] choose_hike else # If input isn't recognized, have user choose a region again choose_region end end
list_hike_details(hike)
click to toggle source
Lists details for selected hike
# File lib/washington_hikes/cli.rb, line 109 def list_hike_details(hike) hike.add_hike_details puts "\n\n----------------------------" puts "\n#{hike.name}" puts "Region: #{hike.region.name}" puts "Length: #{hike.length} miles, #{hike.type}" puts "Elevation Gain: #{hike.elevation_gain}" puts "Rating: #{hike.rating} / 5" puts "Features: #{hike.features.join(", ")}" puts "" puts "#{hike.description}" puts "\n----------------------------\n \n" end
list_hikes(hikes)
click to toggle source
Lists hikes in selected region
# File lib/washington_hikes/cli.rb, line 102 def list_hikes(hikes) hikes.each.with_index(1) {|hike,i| puts "#{i}. #{hike.name} -- #{hike.length} miles, #{hike.type} -- #{hike.elevation_gain}"} end
list_regions(regions)
click to toggle source
Lists regions
# File lib/washington_hikes/cli.rb, line 60 def list_regions(regions) regions.each.with_index(1) do |region,i| puts "#{i}. #{region.name}" puts " #{region.common_landscape_features.join(", ")}" puts " Average Hike Rating: #{region.average_hike_rating}\n " end end
start()
click to toggle source
# File lib/washington_hikes/cli.rb, line 4 def start puts "\n\nWelcome to Washington Hikes!" puts "\n\nFinding the most popular hikes across Washington..." WashingtonHikes::Hike.create_from_wta @region = "all" welcome end
welcome()
click to toggle source
Determine if the user wants to find hikes in a region or browse hikes across Washington
# File lib/washington_hikes/cli.rb, line 15 def welcome puts "\n\nWhat would you like to do?" puts "1. Find the most popular hikes in a specific region of Washington" puts "2. Browse the most popular hikes across Washington" puts "3. Exit the app.\n " puts "Type '1', '2', or '3' to choose." input = gets.chomp case input when "1" choose_region when "2" choose_hike when "3" exit else welcome end end
what_next?()
click to toggle source
Prompts user to take another action after seeing hike details
# File lib/washington_hikes/cli.rb, line 126 def what_next? puts "\n\nWhat would you like to do next?\n " puts "1. See more popular hikes in this region." puts "2. See popular hikes across Washington." puts "3. Choose a different region." puts "4. Exit the app.\n " puts "Type '1', '2', '3' or '4' to choose." input = gets.chomp case input when "1" choose_hike # User can choose a hike from the region the current hike is in when "2" @region = "all" # User can choose a hike from all hikes choose_hike when "3" choose_region # User can choose a new region to brose when "4" exit # Exit the app else what_next? # If input isn't recognized, prompt user again end end