Class: SportsDataApi::Mlb::Game

Inherits:
Object
  • Object
show all
Defined in:
lib/sports_data_api/mlb/game.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Game

Returns a new instance of Game.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/sports_data_api/mlb/game.rb', line 8

def initialize(args={})
  xml = args.fetch(:xml)
  @year = args[:year] ? args[:year].to_i : nil

  xml = xml.first if xml.is_a? Nokogiri::XML::NodeSet
  if xml.is_a? Nokogiri::XML::Element
    @id = xml['id']
    @scheduled = Time.parse(xml.xpath('scheduled_start').children.first.to_s)
    @home = xml['home']
    @away = xml['visitor']
    @status = xml['status']
    @venue = xml['venue']
    @broadcast = Broadcast.new(xml.xpath('broadcast'))
    rescheduled_from = xml.xpath('rescheduled_from')
    if rescheduled_from.count > 0
      @rescheduled_reason = rescheduled_from.first['reason']
      @rescheduled_from = Time.parse(rescheduled_from.first.children.first.to_s)
    end
  end
end

Instance Attribute Details

#awayObject (readonly)

Returns the value of attribute away.



4
5
6
# File 'lib/sports_data_api/mlb/game.rb', line 4

def away
  @away
end

#away_teamObject (readonly)

Returns the value of attribute away_team.



4
5
6
# File 'lib/sports_data_api/mlb/game.rb', line 4

def away_team
  @away_team
end

#broadcastObject (readonly)

Returns the value of attribute broadcast.



4
5
6
# File 'lib/sports_data_api/mlb/game.rb', line 4

def broadcast
  @broadcast
end

#clockObject (readonly)

Returns the value of attribute clock.



4
5
6
# File 'lib/sports_data_api/mlb/game.rb', line 4

def clock
  @clock
end

#dateObject (readonly)

Returns the value of attribute date.



4
5
6
# File 'lib/sports_data_api/mlb/game.rb', line 4

def date
  @date
end

#homeObject (readonly)

Returns the value of attribute home.



4
5
6
# File 'lib/sports_data_api/mlb/game.rb', line 4

def home
  @home
end

#home_teamObject (readonly)

Returns the value of attribute home_team.



4
5
6
# File 'lib/sports_data_api/mlb/game.rb', line 4

def home_team
  @home_team
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/sports_data_api/mlb/game.rb', line 4

def id
  @id
end

#quarterObject (readonly)

Returns the value of attribute quarter.



4
5
6
# File 'lib/sports_data_api/mlb/game.rb', line 4

def quarter
  @quarter
end

#rescheduled_fromObject (readonly)

Returns the value of attribute rescheduled_from.



4
5
6
# File 'lib/sports_data_api/mlb/game.rb', line 4

def rescheduled_from
  @rescheduled_from
end

#rescheduled_reasonObject (readonly)

Returns the value of attribute rescheduled_reason.



4
5
6
# File 'lib/sports_data_api/mlb/game.rb', line 4

def rescheduled_reason
  @rescheduled_reason
end

#scheduledObject (readonly)

Returns the value of attribute scheduled.



4
5
6
# File 'lib/sports_data_api/mlb/game.rb', line 4

def scheduled
  @scheduled
end

#seasonObject (readonly)

Returns the value of attribute season.



4
5
6
# File 'lib/sports_data_api/mlb/game.rb', line 4

def season
  @season
end

#statusObject (readonly)

Returns the value of attribute status.



4
5
6
# File 'lib/sports_data_api/mlb/game.rb', line 4

def status
  @status
end

#venueObject (readonly)

Returns the value of attribute venue.



4
5
6
# File 'lib/sports_data_api/mlb/game.rb', line 4

def venue
  @venue
end

#yearObject (readonly)

Returns the value of attribute year.



4
5
6
# File 'lib/sports_data_api/mlb/game.rb', line 4

def year
  @year
end