Class: Discord::Collection
- Inherits:
-
Object
- Object
- Discord::Collection
- Defined in:
- lib/discord/collection.rb
Instance Attribute Summary collapse
-
#cursor ⇒ Object
readonly
Returns the value of attribute cursor.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data:, total:, cursor: nil) ⇒ Collection
constructor
A new instance of Collection.
Constructor Details
#initialize(data:, total:, cursor: nil) ⇒ Collection
Returns a new instance of Collection.
15 16 17 18 19 |
# File 'lib/discord/collection.rb', line 15 def initialize(data:, total:, cursor:nil) @data = data @total = total @cursor = cursor.nil? ? nil : cursor end |
Instance Attribute Details
#cursor ⇒ Object (readonly)
Returns the value of attribute cursor.
3 4 5 |
# File 'lib/discord/collection.rb', line 3 def cursor @cursor end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
3 4 5 |
# File 'lib/discord/collection.rb', line 3 def data @data end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
3 4 5 |
# File 'lib/discord/collection.rb', line 3 def total @total end |
Class Method Details
.from_response(response, type:) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/discord/collection.rb', line 5 def self.from_response(response, type:) body = response.body new( data: body.map { |attrs| type.new(attrs) }, total: body.count, # cursor: body.dig("pagination", "cursor") ) end |