Class: NHLStats::Conference

Inherits:
Object
  • Object
show all
Defined in:
lib/nhl_stats/conference.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conference_data) ⇒ Conference

Returns a new instance of Conference.



5
6
7
8
# File 'lib/nhl_stats/conference.rb', line 5

def initialize(conference_data)
  @id = conference_data["id"]
  @name = conference_data["name"]
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/nhl_stats/conference.rb', line 3

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/nhl_stats/conference.rb', line 3

def name
  @name
end

Class Method Details

.find(id) ⇒ Object



10
11
12
13
14
# File 'lib/nhl_stats/conference.rb', line 10

def self.find(id)
  response = Faraday.get("#{API_ROOT}/conferences/#{id}")
  attributes = JSON.parse(response.body).dig("conferences", 0)
  new(attributes)
end

.listObject



16
17
18
19
20
21
# File 'lib/nhl_stats/conference.rb', line 16

def self.list
  response = Faraday.get("#{API_ROOT}/conferences")
  JSON.parse(response.body).
    dig("conferences").
    map { |c| NHLStats::Conference.new(c) }
end