Class: SimpleSpotify::Model::Collection
- Inherits:
-
Array
- Object
- Array
- SimpleSpotify::Model::Collection
- Defined in:
- lib/simplespotify/models/collection.rb
Instance Attribute Summary collapse
-
#total ⇒ Object
Returns the value of attribute total.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data, property = :items) ⇒ Collection
constructor
A new instance of Collection.
- #more ⇒ Object
- #more? ⇒ Boolean
Constructor Details
#initialize(data, property = :items) ⇒ Collection
Returns a new instance of Collection.
26 27 28 29 30 31 |
# File 'lib/simplespotify/models/collection.rb', line 26 def initialize data, property=:items values = data[property] super values @total = data[:total] || self.count @next = data[:next] end |
Instance Attribute Details
#total ⇒ Object
Returns the value of attribute total.
6 7 8 |
# File 'lib/simplespotify/models/collection.rb', line 6 def total @total end |
Class Method Details
.of(type, collection) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/simplespotify/models/collection.rb', line 8 def self.of type, collection if type.is_a? Class model = type; prop = type.to_s.split('::').last.downcase+'s' else model_name = type.to_s.gsub(/s$/, '') model = Model.const_get(model_name.capitalize) prop = model_name+'s' end collection = {items: collection} unless collection.is_a? Hash prop = collection.has_key?(prop.to_sym) ? prop.to_sym : :items collection[prop].map! {|item| model.new(item) } self.new(collection) end |
Instance Method Details
#more ⇒ Object
44 45 46 47 48 |
# File 'lib/simplespotify/models/collection.rb', line 44 def more return [] unless more? req = Request.new({endpoint: @next, private: false}) SimpleSpotify.dispatch(req) end |
#more? ⇒ Boolean
39 40 41 |
# File 'lib/simplespotify/models/collection.rb', line 39 def more? !@next.nil? end |