Sha256: 5074193a6ebb743cd40e1c30afc630227a60e4f03c8a9313e4a7e34f01902b18
Contents?: true
Size: 971 Bytes
Versions: 9
Compression:
Stored size: 971 Bytes
Contents
module SportsDataApi module Mlb class Players include Enumerable ## # Initialize by passing the raw XML returned from the API def initialize(xml) @players = [] xml = xml.first if xml.is_a? Nokogiri::XML::NodeSet if xml.is_a? Nokogiri::XML::Element xml.xpath('team').each do |team| team.xpath('players').xpath('player').each do |player| p = Player.new(player, team['id']) @players << p end end end @players end def [](search_index) found_index = @teams.index(search_index) unless found_index.nil? @teams[found_index] end end ## # Make the class Enumerable def each(&block) @players.each do |player| if block_given? block.call player else yield player end end end end end end
Version data entries
9 entries across 9 versions & 1 rubygems