Class: Beatport::Collection

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/beatport/collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, data) ⇒ Collection

Returns a new instance of Collection.

Raises:

  • (ArgumentError)


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['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_filtersObject (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_facetsObject (readonly)

Returns the value of attribute applied_facets.



12
13
14
# File 'lib/beatport/collection.rb', line 12

def applied_facets
  @applied_facets
end

#countObject (readonly)

Returns the value of attribute count.



11
12
13
# File 'lib/beatport/collection.rb', line 11

def count
  @count
end

#date_filtersObject (readonly)

Returns the value of attribute date_filters.



13
14
15
# File 'lib/beatport/collection.rb', line 13

def date_filters
  @date_filters
end

#facetsObject (readonly)

Returns the value of attribute facets.



12
13
14
# File 'lib/beatport/collection.rb', line 12

def facets
  @facets
end

#hostObject (readonly)

Returns the value of attribute host.



10
11
12
# File 'lib/beatport/collection.rb', line 10

def host
  @host
end

#next_queryObject (readonly)

Returns the value of attribute next_query.



10
11
12
# File 'lib/beatport/collection.rb', line 10

def next_query
  @next_query
end

#pageObject (readonly)

Returns the value of attribute page.



11
12
13
# File 'lib/beatport/collection.rb', line 11

def page
  @page
end

#pathObject (readonly)

Returns the value of attribute path.



10
11
12
# File 'lib/beatport/collection.rb', line 10

def path
  @path
end

#per_pageObject (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_optionsObject (readonly)

Returns the value of attribute per_page_options.



11
12
13
# File 'lib/beatport/collection.rb', line 11

def per_page_options
  @per_page_options
end

#queryObject (readonly)

Returns the value of attribute query.



10
11
12
# File 'lib/beatport/collection.rb', line 10

def query
  @query
end

#spellcheckObject (readonly)

Returns the value of attribute spellcheck.



12
13
14
# File 'lib/beatport/collection.rb', line 12

def spellcheck
  @spellcheck
end

#total_pagesObject (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

#groupedObject



32
33
34
# File 'lib/beatport/collection.rb', line 32

def grouped
  group_by { |i| i.type.capitalize }
end