Class: CloudappExport::ItemList
- Inherits:
-
Object
- Object
- CloudappExport::ItemList
- Defined in:
- lib/cloudapp_export/item_list.rb
Instance Attribute Summary collapse
-
#limit ⇒ Object
writeonly
Restrict items to a subset from 0 to $number.
Instance Method Summary collapse
- #count ⇒ Object
- #data ⇒ Object
- #each(&block) ⇒ Object
- #each_with_index(&block) ⇒ Object
-
#initialize(api, options = {}) ⇒ ItemList
constructor
A new instance of ItemList.
- #total_count ⇒ Object
Constructor Details
#initialize(api, options = {}) ⇒ ItemList
Returns a new instance of ItemList.
6 7 8 9 10 11 12 13 |
# File 'lib/cloudapp_export/item_list.rb', line 6 def initialize(api, = {}) @api = api @items = [] @cache_key = ['cache_key'] @use_cache = ['use_cache'] @limit = (['limit'] || 999_999_999).to_i @offset = (['offset'] || 0).to_i end |
Instance Attribute Details
#limit=(value) ⇒ Object (writeonly)
Restrict items to a subset from 0 to $number
42 43 44 |
# File 'lib/cloudapp_export/item_list.rb', line 42 def limit=(value) @limit = value end |
Instance Method Details
#count ⇒ Object
20 21 22 |
# File 'lib/cloudapp_export/item_list.rb', line 20 def count [total_count, @limit].min end |
#data ⇒ Object
15 16 17 18 |
# File 'lib/cloudapp_export/item_list.rb', line 15 def data load @items end |
#each(&block) ⇒ Object
29 30 31 32 |
# File 'lib/cloudapp_export/item_list.rb', line 29 def each(&block) load @items[@offset..(@limit - 1)].each(&block) end |
#each_with_index(&block) ⇒ Object
34 35 36 37 |
# File 'lib/cloudapp_export/item_list.rb', line 34 def each_with_index(&block) load @items[@offset..(@limit - 1)].each_with_index(&block) end |
#total_count ⇒ Object
24 25 26 27 |
# File 'lib/cloudapp_export/item_list.rb', line 24 def total_count @meta['count'].to_i end |