Class: ITuner::Collection
- Inherits:
-
Object
- Object
- ITuner::Collection
- Includes:
- Enumerable
- Defined in:
- lib/ituner/collection.rb
Instance Attribute Summary collapse
-
#app_collection ⇒ Object
readonly
Returns the value of attribute app_collection.
-
#item_class ⇒ Object
readonly
Returns the value of attribute item_class.
-
#item_type ⇒ Object
readonly
Returns the value of attribute item_type.
Instance Method Summary collapse
- #create(properties = {}) ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
- #first ⇒ Object
- #get(index) ⇒ Object (also: #[])
-
#initialize(app_collection, item_type, item_class, &block) ⇒ Collection
constructor
A new instance of Collection.
- #inspect ⇒ Object
- #last ⇒ Object
- #size ⇒ Object
- #translate_index(index) ⇒ Object
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_collection ⇒ Object (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_class ⇒ Object (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_type ⇒ Object (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 |
#each ⇒ Object
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
38 39 40 |
# File 'lib/ituner/collection.rb', line 38 def empty? size == 0 end |
#first ⇒ Object
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 |
#inspect ⇒ Object
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 |
#last ⇒ Object
54 55 56 |
# File 'lib/ituner/collection.rb', line 54 def last wrap_item(app_collection.last.get) end |
#size ⇒ Object
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 |