Class: WaTrailRuns::CLI
- Inherits:
-
Object
- Object
- WaTrailRuns::CLI
- Defined in:
- lib/wa_trail_runs/cli.rb
Overview
CLI Controller
Instance Method Summary collapse
Instance Method Details
#call ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/wa_trail_runs/cli.rb', line 4 def call puts "Welcome to WaTrailRuns, your go-to source for upcoming trail races in Washington State!" sleep 0.5 WaTrailRuns::Scraper.new.scrape_evergreen WaTrailRuns::Scraper.new.scrape_northwest list_runs goodbye end |
#goodbye ⇒ Object
41 42 43 |
# File 'lib/wa_trail_runs/cli.rb', line 41 def goodbye puts "Happy trails!" end |
#list_runs ⇒ Object
14 15 16 17 18 19 |
# File 'lib/wa_trail_runs/cli.rb', line 14 def list_runs puts "Check out the upcoming runs!" WaTrailRuns::Run.all.each.with_index(1) do |run, index| puts "#{index}. #{run.title} - #{run.date}" end end |
#menu ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/wa_trail_runs/cli.rb', line 21 def input = nil while input != "exit" puts "Enter the number of the run you would like to learn more about, 'list' to show the list of runs, or 'exit'." input = gets.strip.downcase range = (1..WaTrailRuns::Run.all.size) if input.to_i > 0 && range.include?(input.to_i) chosen_run = WaTrailRuns::Run.all[input.to_i - 1] puts "#{chosen_run.title}: DESCRIPTION: #{chosen_run.description} MORE INFO: #{chosen_run.info_url} SIGN UP: #{chosen_run.reg_url}" elsif input == "list" list_runs elsif input != 'list' && input != 'exit' puts "Invalid input. Type 'list' to see the runs or 'exit' to quit." end end end |