Class: ZohoInvoiceResource::Collection
- Inherits:
-
ActiveResource::Collection
- Object
- ActiveResource::Collection
- ZohoInvoiceResource::Collection
- Defined in:
- lib/zoho_invoice_resource/collection.rb
Instance Attribute Summary collapse
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#pages ⇒ Object
readonly
Returns the value of attribute pages.
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
-
#total_pages ⇒ Object
readonly
Returns the value of attribute total_pages.
Instance Method Summary collapse
- #collect! ⇒ Object
- #elements ⇒ Object
-
#initialize(hash) ⇒ Collection
constructor
A new instance of Collection.
- #merge!(another) ⇒ Object
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
#page ⇒ Object (readonly)
Returns the value of attribute page.
3 4 5 |
# File 'lib/zoho_invoice_resource/collection.rb', line 3 def page @page end |
#pages ⇒ Object (readonly)
Returns the value of attribute pages.
3 4 5 |
# File 'lib/zoho_invoice_resource/collection.rb', line 3 def pages @pages end |
#per_page ⇒ Object (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 |
#total ⇒ Object (readonly)
Returns the value of attribute total.
3 4 5 |
# File 'lib/zoho_invoice_resource/collection.rb', line 3 def total @total end |
#total_pages ⇒ Object (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 |
#elements ⇒ Object
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 |