Class: Brewerydb::BaseCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/brewerydb/base_collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(items, options = {}) ⇒ BaseCollection

Returns a new instance of BaseCollection.



6
7
8
9
10
# File 'lib/brewerydb/base_collection.rb', line 6

def initialize(items, options = {})
  klass = Brewerydb.const_get(ActiveSupport::Inflector.singularize(self.class.name))
  @items =  Array(items).map { |i| i.is_a?(klass) ? i : klass.new(i) }
  @options = options
end

Instance Method Details

#current_pageObject



16
17
18
# File 'lib/brewerydb/base_collection.rb', line 16

def current_page
  @options["currentPage"]
end

#itemsObject



12
13
14
# File 'lib/brewerydb/base_collection.rb', line 12

def items
  @items
end

#number_of_pagesObject



20
21
22
# File 'lib/brewerydb/base_collection.rb', line 20

def number_of_pages
  @options["numberOfPages"]
end