Sha256: 93d10340d433e8aefc8a07d15acd1cd1453cc3eff2895a98294bf451abb95aef
Contents?: true
Size: 903 Bytes
Versions: 9
Compression:
Stored size: 903 Bytes
Contents
module SportsDataApi module Mlb class Teams include Enumerable attr_reader :leagues, :divisions ## # Initialize by passing the raw XML returned from the API def initialize(xml) @teams = [] xml = xml.first if xml.is_a? Nokogiri::XML::NodeSet if xml.is_a? Nokogiri::XML::Element xml.xpath('//team').each do |team| @teams << Team.new(team) if !team['league'].empty? end end @teams 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) @teams.each do |team| if block_given? block.call team else yield team end end end end end end
Version data entries
9 entries across 9 versions & 1 rubygems