Class: Nbascores::CLI
- Inherits:
-
Object
- Object
- Nbascores::CLI
- Defined in:
- lib/nbascores/cli.rb
Instance Method Summary collapse
- #call ⇒ Object
- #list ⇒ Object
- #newdate ⇒ Object
- #show_score(date) ⇒ Object
- #show_summary(date) ⇒ Object
- #today ⇒ Object
Instance Method Details
#call ⇒ Object
5 6 7 |
# File 'lib/nbascores/cli.rb', line 5 def call list end |
#list ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/nbascores/cli.rb', line 9 def list selection = "" until selection == "3" puts "Enter 1 to refresh today's scores" puts "Enter 2 to see another day's scores" puts "Enter 3 to exit" selection = gets.strip puts "*************************" case selection when "1" show_score(today) NBAStat.find_by_date(today) != [] ? show_summary(today) : (puts "No games or invalid date") when "2" date = newdate show_score(date) NBAStat.find_by_date(date) != [] ? show_summary(date) : (puts "No games or invalid date") when "3" puts "Good-bye" else puts "Invalid selection." end puts "*************************" end end |
#newdate ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/nbascores/cli.rb', line 38 def newdate begin puts "Please enter year in YYYYMMDD format" date = gets.strip url = "http://data.nba.com/data/1h/json/cms/noseason/scoreboard/#{date}/games.json" open(url) rescue OpenURI::HTTPError else date end end |
#show_score(date) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/nbascores/cli.rb', line 50 def show_score(date) Nbascores::Nbascrape.scrape(date) NBAStat.find_by_date(date).each_with_index do |game,i| puts "#{i+1}. #{game.away} - #{game.away_score} #{game.home} - #{game.home_score} #{game.period}" end puts "*************************" end |
#show_summary(date) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/nbascores/cli.rb', line 58 def show_summary(date) selection = "" until selection == NBAStat.find_by_date(date).size+1 puts "Enter 1-#{NBAStat.find_by_date(date).size} to see the game's preview or recap" puts "Enter #{(NBAStat.find_by_date(date).size+1).to_s} to return to main menu" selection = gets.strip.to_i case selection when 1..NBAStat.find_by_date(date).size puts "*************************" puts NBAStat.find_by_date(date)[selection-1].summary_scrape puts "*************************" when NBAStat.find_by_date(date).size+1 #returns to main menu else puts "*************************" puts "Invalid selection." puts "*************************" end end end |
#today ⇒ Object
34 35 36 |
# File 'lib/nbascores/cli.rb', line 34 def today Time.now.strftime("%Y%m%d") end |