Class: SportsDataApi::Mlb::GameStat

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ GameStat



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/sports_data_api/mlb/game_stat.rb', line 5

def initialize(xml)
  if xml.is_a? Nokogiri::XML::Element
    stat_ivar = self.instance_variable_set("@#{xml.name}", {})
    self.class.class_eval { attr_reader :"#{xml.name}" }

    xml.attributes.each do | attr_name, attr_value|
      stat_ivar[attr_name.to_sym] = attr_value.value
    end

    xml.xpath('.//*').each do |other_stat|
      if other_stat.is_a? Nokogiri::XML::Element
        stat_ivar[other_stat.name.to_sym] = {}
        other_stat.attributes.each do | attr_name, attr_value|
          stat_ivar[other_stat.name.to_sym][attr_name.to_sym] = attr_value.value
        end
      end
    end
  end
end

Instance Attribute Details

#player_idObject (readonly)

Returns the value of attribute player_id.



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

def player_id
  @player_id
end