Class: SportsDataApi::Mlb::Teams
- Inherits:
-
Object
- Object
- SportsDataApi::Mlb::Teams
- Includes:
- Enumerable
- Defined in:
- lib/sports_data_api/mlb/teams.rb
Instance Attribute Summary collapse
-
#divisions ⇒ Object
readonly
Returns the value of attribute divisions.
-
#leagues ⇒ Object
readonly
Returns the value of attribute leagues.
Instance Method Summary collapse
- #[](search_index) ⇒ Object
-
#each(&block) ⇒ Object
Make the class Enumerable.
-
#initialize(xml) ⇒ Teams
constructor
Initialize by passing the raw XML returned from the API.
Constructor Details
#initialize(xml) ⇒ Teams
Initialize by passing the raw XML returned from the API
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/sports_data_api/mlb/teams.rb', line 10 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 |
Instance Attribute Details
#divisions ⇒ Object (readonly)
Returns the value of attribute divisions.
6 7 8 |
# File 'lib/sports_data_api/mlb/teams.rb', line 6 def divisions @divisions end |
#leagues ⇒ Object (readonly)
Returns the value of attribute leagues.
6 7 8 |
# File 'lib/sports_data_api/mlb/teams.rb', line 6 def leagues @leagues end |
Instance Method Details
#[](search_index) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/sports_data_api/mlb/teams.rb', line 22 def [](search_index) found_index = @teams.index(search_index) unless found_index.nil? @teams[found_index] end end |
#each(&block) ⇒ Object
Make the class Enumerable
31 32 33 34 35 36 37 38 39 |
# File 'lib/sports_data_api/mlb/teams.rb', line 31 def each(&block) @teams.each do |team| if block_given? block.call team else yield team end end end |