Class: Gameday
Constant Summary
Constants included from Helpers
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#games ⇒ Object
readonly
Returns the value of attribute games.
Instance Method Summary collapse
- #game_from_team(team) ⇒ Object
-
#initialize(year, month, day) ⇒ Gameday
constructor
A new instance of Gameday.
Methods included from Helpers
#boxscore, #build_base_url, #generate_nokogiri_html, #generate_nokogiri_xml, #valid_game?
Constructor Details
#initialize(year, month, day) ⇒ Gameday
Returns a new instance of Gameday.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/mlb_gd2/gameday.rb', line 12 def initialize(year, month, day) date_time = Time.new(year, month, day) base_url = build_base_url(date_time) @games = [] generate_nokogiri_html(base_url).search('a[href^="gid"]').each do |link| gid = link.attributes["href"].value if valid_game?(base_url + gid) @games << Game.new(base_url + gid) end end @date = date_time.strftime("%B %-d, %Y") end |
Instance Attribute Details
#date ⇒ Object (readonly)
Returns the value of attribute date.
10 11 12 |
# File 'lib/mlb_gd2/gameday.rb', line 10 def date @date end |
#games ⇒ Object (readonly)
Returns the value of attribute games.
10 11 12 |
# File 'lib/mlb_gd2/gameday.rb', line 10 def games @games end |
Instance Method Details
#game_from_team(team) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/mlb_gd2/gameday.rb', line 26 def game_from_team(team) if team.downcase.include? "angels" tid = "ana" elsif team.downcase.include? "astros" tid = "hou" elsif team.downcase.include? "athletics" tid = "oak" elsif team.downcase.include? "blue jays" tid = "tor" elsif team.downcase.include? "braves" tid = "atl" elsif team.downcase.include? "brewers" tid = "mil" elsif team.downcase.include? "cardinals" tid = "sln" elsif team.downcase.include? "cubs" tid = "chn" elsif team.downcase.include? "diamondbacks" tid = "ari" elsif team.downcase.include? "dodgers" tid = "lan" elsif team.downcase.include? "giants" tid = "sfn" elsif team.downcase.include? "indians" tid = "cle" elsif team.downcase.include? "mariners" tid = "sea" elsif team.downcase.include? "marlins" tid = "mia" elsif team.downcase.include? "mets" tid = "nyn" elsif team.downcase.include? "nationals" tid = "was" elsif team.downcase.include? "orioles" tid = "bal" elsif team.downcase.include? "padres" tid = "sdn" elsif team.downcase.include? "pillies" tid = "phi" elsif team.downcase.include? "pirates" tid = "pit" elsif team.downcase.include? "rangers" tid = "tex" elsif team.downcase.include? "rays" tid = "tba" elsif team.downcase.include? "red sox" tid = "bos" elsif team.downcase.include? "reds" tid = "cin" elsif team.downcase.include? "rockies" tid = "col" elsif team.downcase.include? "royals" tid = "kca" elsif team.downcase.include? "tigers" tid = "det" elsif team.downcase.include? "twins" tid = "min" elsif team.downcase.include? "white sox" tid = "cha" elsif team.downcase.include? "yankees" tid = "nya" else tid = "invalid query" end selected_games = games.select { |game| game.url.include?(tid) || game.url.include?(tid) } if selected_games.length > 1 puts "That query fits more than one game. Please be more specific." elsif selected_games.empty? puts "No teams match that query." else selected_games[0] end end |