Class: RaceFinder::CLI
- Inherits:
-
Object
- Object
- RaceFinder::CLI
- Defined in:
- lib/race_finder/cli.rb
Instance Method Summary collapse
Instance Method Details
#call ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/race_finder/cli.rb', line 5 def call puts "Welcome racers!" #get_state make_races puts "On your mark!" sleep 1 puts "Get set!" sleep 1 puts "Go!" list_races race_details end |
#get_state ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/race_finder/cli.rb', line 19 def get_state puts "Type in the 2-letter code for the state you would like to search:" state_code = gets.strip.upcase if /\b\D{2}\b/.match?(state_code) state_code else puts "Please enter a valid 2-letter state code" get_state end end |
#list_races ⇒ Object
54 55 56 57 58 |
# File 'lib/race_finder/cli.rb', line 54 def list_races RaceFinder::Race.all.each_with_index do |race, i| puts "#{i+1}. #{race.title} - #{race.date} - #{race.location}" end end |
#make_races ⇒ Object
50 51 52 |
# File 'lib/race_finder/cli.rb', line 50 def make_races RaceFinder::Scraper.scrape_race_index("http://www.runnersworld.com/race-finder/results?state=#{get_state}&by_location=1") end |
#race_details ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/race_finder/cli.rb', line 32 def race_details puts "Enter the number of the race you would like to view:" race_choice = gets.to_i if race_choice.between?(1,25) RaceFinder::Scraper.scrape_details("http://www.runnersworld.com#{RaceFinder::Race.all[race_choice-1].url}") else puts "Please enter a valid number" race_details end puts "Would you like to view another race?" answer = gets.strip.upcase if answer == "YES" race_details else puts "Goodbye!" end end |