Class: BikeReg::Collection

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data:, total:, start_page:) ⇒ Collection

Returns a new instance of Collection.



16
17
18
19
20
21
# File 'lib/bike_reg/collection.rb', line 16

def initialize(data:, total:, start_page:)
  @data = data
  @total = total
  @next_page = start_page.nil? ? 1 : start_page + 1
  @prev_page = start_page.nil? ? 0 : start_page - 1
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



5
6
7
# File 'lib/bike_reg/collection.rb', line 5

def data
  @data
end

#next_pageObject (readonly)

Returns the value of attribute next_page.



5
6
7
# File 'lib/bike_reg/collection.rb', line 5

def next_page
  @next_page
end

#prev_pageObject (readonly)

Returns the value of attribute prev_page.



5
6
7
# File 'lib/bike_reg/collection.rb', line 5

def prev_page
  @prev_page
end

#totalObject (readonly)

Returns the value of attribute total.



5
6
7
# File 'lib/bike_reg/collection.rb', line 5

def total
  @total
end

Class Method Details

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



7
8
9
10
11
12
13
14
# File 'lib/bike_reg/collection.rb', line 7

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