Class: ZohoInvoiceResource::Collection

Inherits:
ActiveResource::Collection
  • Object
show all
Defined in:
lib/zoho_invoice_resource/collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Collection

Returns a new instance of Collection.



4
5
6
7
8
9
10
11
12
13
# File 'lib/zoho_invoice_resource/collection.rb', line 4

def initialize(hash)
  @element_hash = hash
  if hash['PageContext']
    @page = hash['PageContext']['Page'].to_i
    @pages = [@page]
    @per_page = hash['PageContext']['Per_Page'].to_i
    @total = hash['PageContext']['Total'].to_i
    @total_pages = hash['PageContext']['Total_Pages'].to_i
  end
end

Instance Attribute Details

#pageObject (readonly)

Returns the value of attribute page.



3
4
5
# File 'lib/zoho_invoice_resource/collection.rb', line 3

def page
  @page
end

#pagesObject (readonly)

Returns the value of attribute pages.



3
4
5
# File 'lib/zoho_invoice_resource/collection.rb', line 3

def pages
  @pages
end

#per_pageObject (readonly)

Returns the value of attribute per_page.



3
4
5
# File 'lib/zoho_invoice_resource/collection.rb', line 3

def per_page
  @per_page
end

#totalObject (readonly)

Returns the value of attribute total.



3
4
5
# File 'lib/zoho_invoice_resource/collection.rb', line 3

def total
  @total
end

#total_pagesObject (readonly)

Returns the value of attribute total_pages.



3
4
5
# File 'lib/zoho_invoice_resource/collection.rb', line 3

def total_pages
  @total_pages
end

Instance Method Details

#collect!Object



22
23
24
25
# File 'lib/zoho_invoice_resource/collection.rb', line 22

def collect!
  elements # prepare @elements
  super
end

#elementsObject



15
16
17
18
19
20
# File 'lib/zoho_invoice_resource/collection.rb', line 15

def elements
  @elements ||= begin
    name = resource_class.name
    @element_hash[name.pluralize][name]
  end
end

#merge!(another) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/zoho_invoice_resource/collection.rb', line 27

def merge!(another)
  another.each do |element|
    elements << element
  end
  @pages = [@page, another.page].flatten
  @page = another.page
  @per_page = another.per_page
  @total = another.total
  @total_pages = another.total_pages
end