class SportsDataApi::Nhl::Teams

Attributes

json[R]

Public Class Methods

new(json) click to toggle source
# File lib/sports_data_api/nhl/teams.rb, line 6
def initialize(json)
  @json = json
end

Public Instance Methods

each() { |team| ... } click to toggle source

Make the class Enumerable

# File lib/sports_data_api/nhl/teams.rb, line 22
def each
  return teams.each unless block_given?
  teams.each { |team| yield team }
end
teams() click to toggle source
# File lib/sports_data_api/nhl/teams.rb, line 10
def teams
  @teams ||= json.fetch('conferences', []).flat_map do |conference|
    conference['divisions'].flat_map do |division|
      division['teams'].map do |team_json|
        Team.new(team_json, conference['alias'], division['alias'])
      end
    end
  end
end