Class: Pinata::Collection
- Inherits:
-
Object
- Object
- Pinata::Collection
- Defined in:
- lib/pinata/collection.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#next_page_token ⇒ Object
readonly
Returns the value of attribute next_page_token.
Class Method Summary collapse
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(data:, next_page_token:) ⇒ Collection
constructor
A new instance of Collection.
- #sample ⇒ Object
Constructor Details
#initialize(data:, next_page_token:) ⇒ Collection
Returns a new instance of Collection.
15 16 17 18 |
# File 'lib/pinata/collection.rb', line 15 def initialize(data:, next_page_token:) @data = data @next_page_token = (next_page_token.nil? || next_page_token.empty?) ? nil : next_page_token end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/pinata/collection.rb', line 5 def data @data end |
#next_page_token ⇒ Object (readonly)
Returns the value of attribute next_page_token.
5 6 7 |
# File 'lib/pinata/collection.rb', line 5 def next_page_token @next_page_token end |
Class Method Details
.from_response(response, key:, type:) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/pinata/collection.rb', line 7 def self.from_response(response, key:, type:) body = response.body new( data: body["data"][key].map { |attrs| type.new(attrs) }, next_page_token: body.dig("data", "next_page_token") ) end |
Instance Method Details
#empty? ⇒ Boolean
20 21 22 |
# File 'lib/pinata/collection.rb', line 20 def empty? data.empty? end |
#sample ⇒ Object
24 25 26 |
# File 'lib/pinata/collection.rb', line 24 def sample data.sample end |