Class: FindworkApi::Collection
- Inherits:
-
Object
- Object
- FindworkApi::Collection
- Defined in:
- lib/findwork_api/collection.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#next_page ⇒ Object
readonly
Returns the value of attribute next_page.
-
#previous_page ⇒ Object
readonly
Returns the value of attribute previous_page.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(count:, next_page:, previous_page:, data:) ⇒ Collection
constructor
A new instance of Collection.
Constructor Details
#initialize(count:, next_page:, previous_page:, data:) ⇒ Collection
Returns a new instance of Collection.
16 17 18 19 20 21 |
# File 'lib/findwork_api/collection.rb', line 16 def initialize(count:, next_page:, previous_page:, data:) @count = count @next_page = next_page.nil? ? nil : next_page @previous_page = previous_page.nil? ? nil : previous_page @data = data end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
3 4 5 |
# File 'lib/findwork_api/collection.rb', line 3 def count @count end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
3 4 5 |
# File 'lib/findwork_api/collection.rb', line 3 def data @data end |
#next_page ⇒ Object (readonly)
Returns the value of attribute next_page.
3 4 5 |
# File 'lib/findwork_api/collection.rb', line 3 def next_page @next_page end |
#previous_page ⇒ Object (readonly)
Returns the value of attribute previous_page.
3 4 5 |
# File 'lib/findwork_api/collection.rb', line 3 def previous_page @previous_page end |
Class Method Details
.from_response(response, key:, type:) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/findwork_api/collection.rb', line 5 def self.from_response(response, key:, type:) body = response.body # Nested values can be appended as additional arguments to dig new( count: body.dig("count"), next_page: body.dig("next"), previous_page: body.dig("previous"), data: body[key].map { |attrs| type.new(attrs) } ) end |