Class: BikeReg::Collection
- Inherits:
-
Object
- Object
- BikeReg::Collection
- Defined in:
- lib/bike_reg/collection.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#next_page ⇒ Object
readonly
Returns the value of attribute next_page.
-
#prev_page ⇒ Object
readonly
Returns the value of attribute prev_page.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data:, total:, start_page:) ⇒ Collection
constructor
A new instance of Collection.
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
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/bike_reg/collection.rb', line 5 def data @data end |
#next_page ⇒ Object (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_page ⇒ Object (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 |
#total ⇒ Object (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 |