Class: SportsDataApi::Nhl::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/sports_data_api/nhl/player.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ Player

Returns a new instance of Player.



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

def initialize(xml)
  if xml.is_a? Nokogiri::XML::Element
    player_ivar = self.instance_variable_set("@#{xml.name}", {})
    self.class.class_eval { attr_reader :"#{xml.name}" }
    xml.attributes.each do |attr_name, attr_value|
      player_ivar[attr_name.to_sym] = attr_value.value
    end

    stats_xml = xml.xpath('statistics')
    if stats_xml.is_a? Nokogiri::XML::NodeSet and stats_xml.count > 0
      @stats = SportsDataApi::Stats.new(stats_xml.first)
    end

    if @stats
      goaltending_xml = xml.xpath('goaltending').first
      if goaltending_xml.is_a? Nokogiri::XML::Element
        goaltending_ivar = @stats.instance_variable_set("@#{goaltending_xml.name}", {})
        @stats.class.class_eval { attr_reader :"#{goaltending_xml.name}" }
        goaltending_xml.attributes.each { |attr_name, attr_value| goaltending_ivar[attr_name.to_sym] = attr_value.value }
      end
    end
  end
end

Instance Attribute Details

#statsObject (readonly)

Returns the value of attribute stats.



4
5
6
# File 'lib/sports_data_api/nhl/player.rb', line 4

def stats
  @stats
end