Class: CloudappExport::ItemList

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudapp_export/item_list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  @api = api
  @items = []
  @cache_key = options['cache_key']
  @use_cache = options['use_cache']
  @limit = (options['limit'] || 999_999_999).to_i
  @offset = (options['offset'] || 0).to_i
end

Instance Attribute Details

#limit=(value) ⇒ Object (writeonly)

Restrict items to a subset from 0 to $number

Parameters:

  • number (Integer)

    Number of items to return

Returns:

  • Integer



42
43
44
# File 'lib/cloudapp_export/item_list.rb', line 42

def limit=(value)
  @limit = value
end

Instance Method Details

#countObject



20
21
22
# File 'lib/cloudapp_export/item_list.rb', line 20

def count
  [total_count, @limit].min
end

#dataObject



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_countObject



24
25
26
27
# File 'lib/cloudapp_export/item_list.rb', line 24

def total_count
  load_meta
  @meta['count'].to_i
end