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

Inherits:
Object
  • Object
show all
Defined in:
lib/nfl/live_update/score_strip/games.rb

Constant Summary collapse

LIVE_UPDATE_URL =
"http://www.nfl.com/liveupdate/scorestrip/ss.xml"
POST_SEASON_URL =
"http://www.nfl.com/liveupdate/scorestrip/postseason/ss.xml"
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.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/nfl/live_update/score_strip/games.rb', line 13

def initialize(xml)
  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.



11
12
13
# File 'lib/nfl/live_update/score_strip/games.rb', line 11

def bph
  @bph
end

#gamesObject (readonly)

Returns the value of attribute games.



11
12
13
# File 'lib/nfl/live_update/score_strip/games.rb', line 11

def games
  @games
end

#gdObject (readonly)

Returns the value of attribute gd.



11
12
13
# File 'lib/nfl/live_update/score_strip/games.rb', line 11

def gd
  @gd
end

#typeObject (readonly)

Returns the value of attribute type.



11
12
13
# File 'lib/nfl/live_update/score_strip/games.rb', line 11

def type
  @type
end

#weekObject (readonly)

Returns the value of attribute week.



11
12
13
# File 'lib/nfl/live_update/score_strip/games.rb', line 11

def week
  @week
end

#yearObject (readonly)

Returns the value of attribute year.



11
12
13
# File 'lib/nfl/live_update/score_strip/games.rb', line 11

def year
  @year
end

Class Method Details

.get(url) ⇒ Object



63
64
65
# File 'lib/nfl/live_update/score_strip/games.rb', line 63

def get(url)
  Nokogiri::XML(open(url))
end

.post_seasonObject



48
49
50
# File 'lib/nfl/live_update/score_strip/games.rb', line 48

def post_season
  new(get(POST_SEASON_URL))
end

.regular_seasonObject



44
45
46
# File 'lib/nfl/live_update/score_strip/games.rb', line 44

def regular_season
  new(get(LIVE_UPDATE_URL))
end

.url(params = {}) ⇒ Object



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

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



59
60
61
# File 'lib/nfl/live_update/score_strip/games.rb', line 59

def where(params)
  new(get(url(params)))
end

Instance Method Details

#type_stringObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/nfl/live_update/score_strip/games.rb', line 31

def type_string
  case @type
  when "R"
    "Regular Season"
  when "POST"
    "Post Season"
  else
    @type
  end
end