Class: ITuner::Collection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ituner/collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_collection, item_type, item_class, &block) ⇒ Collection

Returns a new instance of Collection.



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

def initialize(app_collection, item_type, item_class, &block)
  @app_collection = app_collection
  @item_type = item_type
  @item_class = item_class
  if block
    self.extend(Module.new(&block))
  end
end

Instance Attribute Details

#app_collectionObject (readonly)

Returns the value of attribute app_collection.



14
15
16
# File 'lib/ituner/collection.rb', line 14

def app_collection
  @app_collection
end

#item_classObject (readonly)

Returns the value of attribute item_class.



15
16
17
# File 'lib/ituner/collection.rb', line 15

def item_class
  @item_class
end

#item_typeObject (readonly)

Returns the value of attribute item_type.



16
17
18
# File 'lib/ituner/collection.rb', line 16

def item_type
  @item_type
end

Instance Method Details

#create(properties = {}) ⇒ Object



58
59
60
# File 'lib/ituner/collection.rb', line 58

def create(properties = {})
  wrap_item(ITuner.itunes_app.make(:new => item_type, :with_properties => properties))
end

#eachObject



42
43
44
45
46
# File 'lib/ituner/collection.rb', line 42

def each
  app_collection.get.each do |item|
    yield wrap_item(item)
  end
end

#empty?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/ituner/collection.rb', line 38

def empty?
  size == 0
end

#firstObject



50
51
52
# File 'lib/ituner/collection.rb', line 50

def first
  wrap_item(app_collection.first.get)
end

#get(index) ⇒ Object Also known as: []



18
19
20
21
# File 'lib/ituner/collection.rb', line 18

def get(index)
  app_reference = app_collection[translate_index(index)]
  wrap_item(resolve_reference(app_reference))
end

#inspectObject



62
63
64
65
66
67
68
# File 'lib/ituner/collection.rb', line 62

def inspect
  s = take(10).inspect
  if size > 10
    s[-1,1] = ", (and #{size - 10} more)]" 
  end
  s
end

#lastObject



54
55
56
# File 'lib/ituner/collection.rb', line 54

def last
  wrap_item(app_collection.last.get)
end

#sizeObject



34
35
36
# File 'lib/ituner/collection.rb', line 34

def size
  app_collection.get.size
end

#translate_index(index) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/ituner/collection.rb', line 25

def translate_index(index)
  case index
  when Integer
    index + 1
  else
    index
  end
end