Class: NFL::LiveUpdate::ScoreStrip::Games
- Inherits:
-
Object
- Object
- NFL::LiveUpdate::ScoreStrip::Games
- Includes:
- HTTParty
- Defined in:
- lib/nfl/live_update/score_strip/games.rb
Constant Summary collapse
- AJAX_URL =
"http://www.nfl.com/ajax/scorestrip"
Instance Attribute Summary collapse
-
#bph ⇒ Object
readonly
Returns the value of attribute bph.
-
#games ⇒ Object
readonly
Returns the value of attribute games.
-
#gd ⇒ Object
readonly
Returns the value of attribute gd.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#week ⇒ Object
readonly
Returns the value of attribute week.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Class Method Summary collapse
- .post_season ⇒ Object
- .regular_season ⇒ Object
- .url(params = {}) ⇒ Object
- .where(params) ⇒ Object
- .where_xml(params) ⇒ Object
Instance Method Summary collapse
-
#initialize(xml) ⇒ Games
constructor
A new instance of Games.
- #raw_xml ⇒ Object
- #raw_xml_to_hash ⇒ Object
- #raw_xml_to_json ⇒ Object
- #type_string ⇒ Object
Constructor Details
#initialize(xml) ⇒ Games
Returns a new instance of Games.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/nfl/live_update/score_strip/games.rb', line 20 def initialize(xml) @xml = xml.dup gms = xml.xpath("//ss//gms").first attributes = gms.attributes attributes.each do |k,v| attributes[k] = v.text end @week = attributes["w"] @year = attributes["y"] @type = attributes["t"] @gd = attributes["gd"] @bph = attributes["bph"] @bf = attributes["bf"] @games = gms.xpath("//g").map {|g| Game.new(g) } end |
Instance Attribute Details
#bph ⇒ Object (readonly)
Returns the value of attribute bph.
18 19 20 |
# File 'lib/nfl/live_update/score_strip/games.rb', line 18 def bph @bph end |
#games ⇒ Object (readonly)
Returns the value of attribute games.
18 19 20 |
# File 'lib/nfl/live_update/score_strip/games.rb', line 18 def games @games end |
#gd ⇒ Object (readonly)
Returns the value of attribute gd.
18 19 20 |
# File 'lib/nfl/live_update/score_strip/games.rb', line 18 def gd @gd end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
18 19 20 |
# File 'lib/nfl/live_update/score_strip/games.rb', line 18 def type @type end |
#week ⇒ Object (readonly)
Returns the value of attribute week.
18 19 20 |
# File 'lib/nfl/live_update/score_strip/games.rb', line 18 def week @week end |
#year ⇒ Object (readonly)
Returns the value of attribute year.
18 19 20 |
# File 'lib/nfl/live_update/score_strip/games.rb', line 18 def year @year end |
Class Method Details
.post_season ⇒ Object
70 71 72 |
# File 'lib/nfl/live_update/score_strip/games.rb', line 70 def post_season new(get("/postseason/ss.xml")) end |
.regular_season ⇒ Object
66 67 68 |
# File 'lib/nfl/live_update/score_strip/games.rb', line 66 def regular_season new(get("/ss.xml")) end |
.url(params = {}) ⇒ Object
74 75 76 77 78 79 |
# File 'lib/nfl/live_update/score_strip/games.rb', line 74 def url(params={}) season = params[:season] season_type = params[:season_type] week = params[:week] "#{AJAX_URL}?season=#{season}&seasonType=#{season_type}&week=#{week}" end |
.where(params) ⇒ Object
81 82 83 |
# File 'lib/nfl/live_update/score_strip/games.rb', line 81 def where(params) new(where_xml(params)) end |
.where_xml(params) ⇒ Object
85 86 87 |
# File 'lib/nfl/live_update/score_strip/games.rb', line 85 def where_xml(params) get(url(params)) end |
Instance Method Details
#raw_xml ⇒ Object
52 53 54 |
# File 'lib/nfl/live_update/score_strip/games.rb', line 52 def raw_xml @xml end |
#raw_xml_to_hash ⇒ Object
56 57 58 |
# File 'lib/nfl/live_update/score_strip/games.rb', line 56 def raw_xml_to_hash Hash.from_xml(@xml) end |
#raw_xml_to_json ⇒ Object
60 61 62 |
# File 'lib/nfl/live_update/score_strip/games.rb', line 60 def raw_xml_to_json raw_xml_to_hash.to_json end |
#type_string ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/nfl/live_update/score_strip/games.rb', line 41 def type_string case @type when "R" "Regular Season" when "POST" "Post Season" else @type end end |