Class: Beatport::Collection
- Inherits:
-
Object
- Object
- Beatport::Collection
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/beatport/collection.rb
Instance Attribute Summary collapse
-
#applied_date_filters ⇒ Object
readonly
Returns the value of attribute applied_date_filters.
-
#applied_facets ⇒ Object
readonly
Returns the value of attribute applied_facets.
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#date_filters ⇒ Object
readonly
Returns the value of attribute date_filters.
-
#facets ⇒ Object
readonly
Returns the value of attribute facets.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#next_query ⇒ Object
readonly
Returns the value of attribute next_query.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
-
#per_page_options ⇒ Object
readonly
Returns the value of attribute per_page_options.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#spellcheck ⇒ Object
readonly
Returns the value of attribute spellcheck.
-
#total_pages ⇒ Object
readonly
Returns the value of attribute total_pages.
Instance Method Summary collapse
- #grouped ⇒ Object
-
#initialize(klass, data) ⇒ Collection
constructor
A new instance of Collection.
Constructor Details
#initialize(klass, data) ⇒ Collection
Returns a new instance of Collection.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/beatport/collection.rb', line 15 def initialize(klass, data) raise ArgumentError, "Invalid data passed to Collection.new" unless data.is_a?(Hash) && data['results'].is_a?(Array) data['metadata'].each do |k, v| instance_variable_set(:"@#{k}", v) end @results = if klass == :auto data['results'].map do |r| item_klass = Support::Inflector.constantize("Beatport::Catalog::#{r['type'].capitalize}") item_klass.new(r) end else data['results'].map { |r| klass.new(r) } end end |
Instance Attribute Details
#applied_date_filters ⇒ Object (readonly)
Returns the value of attribute applied_date_filters.
13 14 15 |
# File 'lib/beatport/collection.rb', line 13 def applied_date_filters @applied_date_filters end |
#applied_facets ⇒ Object (readonly)
Returns the value of attribute applied_facets.
12 13 14 |
# File 'lib/beatport/collection.rb', line 12 def applied_facets @applied_facets end |
#count ⇒ Object (readonly)
Returns the value of attribute count.
11 12 13 |
# File 'lib/beatport/collection.rb', line 11 def count @count end |
#date_filters ⇒ Object (readonly)
Returns the value of attribute date_filters.
13 14 15 |
# File 'lib/beatport/collection.rb', line 13 def date_filters @date_filters end |
#facets ⇒ Object (readonly)
Returns the value of attribute facets.
12 13 14 |
# File 'lib/beatport/collection.rb', line 12 def facets @facets end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
10 11 12 |
# File 'lib/beatport/collection.rb', line 10 def host @host end |
#next_query ⇒ Object (readonly)
Returns the value of attribute next_query.
10 11 12 |
# File 'lib/beatport/collection.rb', line 10 def next_query @next_query end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
11 12 13 |
# File 'lib/beatport/collection.rb', line 11 def page @page end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/beatport/collection.rb', line 10 def path @path end |
#per_page ⇒ Object (readonly)
Returns the value of attribute per_page.
11 12 13 |
# File 'lib/beatport/collection.rb', line 11 def per_page @per_page end |
#per_page_options ⇒ Object (readonly)
Returns the value of attribute per_page_options.
11 12 13 |
# File 'lib/beatport/collection.rb', line 11 def @per_page_options end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
10 11 12 |
# File 'lib/beatport/collection.rb', line 10 def query @query end |
#spellcheck ⇒ Object (readonly)
Returns the value of attribute spellcheck.
12 13 14 |
# File 'lib/beatport/collection.rb', line 12 def spellcheck @spellcheck end |
#total_pages ⇒ Object (readonly)
Returns the value of attribute total_pages.
11 12 13 |
# File 'lib/beatport/collection.rb', line 11 def total_pages @total_pages end |
Instance Method Details
#grouped ⇒ Object
32 33 34 |
# File 'lib/beatport/collection.rb', line 32 def grouped group_by { |i| i.type.capitalize } end |