Class: ShootingMatchFinder::CLI
- Inherits:
-
Object
- Object
- ShootingMatchFinder::CLI
- Defined in:
- lib/shooting_match_finder/cli.rb
Constant Summary collapse
- BASE_PATH =
"https://practiscore.com"
Instance Method Summary collapse
-
#add_attributes_to_match ⇒ Object
Adds details to those newly created matches.
-
#create_matches ⇒ Object
Scrapes and then passes an array of hashes to Match.rb.
-
#farewell ⇒ Object
Says goodbye!.
-
#list_matches ⇒ Object
Lists out the created matches by iterating over Match @@all.
-
#menu ⇒ Object
Is able to show details about any match.
- #start ⇒ Object
Instance Method Details
#add_attributes_to_match ⇒ Object
Adds details to those newly created matches.
18 19 20 21 22 23 |
# File 'lib/shooting_match_finder/cli.rb', line 18 def add_attributes_to_match #Adds details to those newly created matches. Match.show_matches.each do |match| attributes = ShootingMatchFinder::Scraper.scrape_from_match_url(BASE_PATH + match.match_url) match.add_attributes(attributes) end end |
#create_matches ⇒ Object
Scrapes and then passes an array of hashes to Match.rb
13 14 15 16 |
# File 'lib/shooting_match_finder/cli.rb', line 13 def create_matches #Scrapes and then passes an array of hashes to Match.rb matches = ShootingMatchFinder::Scraper.scrape_matches(BASE_PATH + '/search/matches') Match.new_from_practiscore(matches) end |
#farewell ⇒ Object
Says goodbye!
51 52 53 |
# File 'lib/shooting_match_finder/cli.rb', line 51 def farewell #Says goodbye! puts "Come back again for more matches!" end |
#list_matches ⇒ Object
Lists out the created matches by iterating over Match @@all.
25 26 27 28 |
# File 'lib/shooting_match_finder/cli.rb', line 25 def list_matches #Lists out the created matches by iterating over Match @@all. puts "Here are the matches in your area:" Match.show_matches.each.with_index(1){|match, i| puts "#{i}. #{match.name}"} end |
#menu ⇒ Object
Is able to show details about any match.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/shooting_match_finder/cli.rb', line 30 def #Is able to show details about any match. input = nil while input != "exit" puts "Enter a match number for more info, list to see matches, or type exit." input = gets.strip if input.to_i > 0 && input.to_i < Match.show_matches.length puts "" puts "#{Match.show_matches[input.to_i - 1].name}" puts " Start Time: #{Match.show_matches[input.to_i - 1].match_start}" puts " Location: #{Match.show_matches[input.to_i - 1].location}" puts " Entry Fee: #{Match.show_matches[input.to_i - 1].entry_fee}" puts " #{Match.show_matches[input.to_i - 1].description}" puts "" elsif input.downcase == "list" list_matches else puts "Please enter a match number, or type exit." end end end |
#start ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/shooting_match_finder/cli.rb', line 5 def start create_matches add_attributes_to_match list_matches farewell end |