Class: PersonaApi::Collection
- Inherits:
-
Object
- Object
- PersonaApi::Collection
- Defined in:
- lib/persona_api/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.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data:, next_page:, prev_page:) ⇒ Collection
constructor
A new instance of Collection.
Constructor Details
#initialize(data:, next_page:, prev_page:) ⇒ Collection
Returns a new instance of Collection.
14 15 16 17 18 |
# File 'lib/persona_api/collection.rb', line 14 def initialize(data:, next_page:, prev_page:) @data = data @next_page = next_page.nil? ? nil : data.last.id @prev_page = prev_page.nil? ? nil : data.first.id end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
3 4 5 |
# File 'lib/persona_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/persona_api/collection.rb', line 3 def next_page @next_page end |
#prev_page ⇒ Object (readonly)
Returns the value of attribute prev_page.
3 4 5 |
# File 'lib/persona_api/collection.rb', line 3 def prev_page @prev_page end |
Class Method Details
.from_response(response, key:, type:) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/persona_api/collection.rb', line 5 def self.from_response(response, key:, type:) body = response.body new( data: body[key].map{ |attrs| type.new(attrs) }, next_page: body.dig("links", "next"), prev_page: body.dig("links", "prev") ) end |