Class: NFL::LiveUpdate::ScoreStrip::Games

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#bphObject (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

#gamesObject (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

#gdObject (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

#typeObject (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

#weekObject (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

#yearObject (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_seasonObject



70
71
72
# File 'lib/nfl/live_update/score_strip/games.rb', line 70

def post_season
  new(get("/postseason/ss.xml"))
end

.regular_seasonObject



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_xmlObject



52
53
54
# File 'lib/nfl/live_update/score_strip/games.rb', line 52

def raw_xml
  @xml
end

#raw_xml_to_hashObject



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_jsonObject



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_stringObject



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