Class: ChessApi::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/chess_api/collection.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data:) ⇒ Collection

Returns a new instance of Collection.



12
13
14
# File 'lib/chess_api/collection.rb', line 12

def initialize(data:)
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



3
4
5
# File 'lib/chess_api/collection.rb', line 3

def data
  @data
end

Class Method Details

.from_response(response, key:, type:) ⇒ Object



5
6
7
8
9
10
# File 'lib/chess_api/collection.rb', line 5

def self.from_response(response, key:, type:)
  body = response.body
  new(
    data: body[key].map { |attrs| type.new(attrs) }
  )
end