Class: ITunes::Playlist

Inherits:
Object
  • Object
show all
Defined in:
lib/itunes/playlist.rb

Instance Method Summary collapse

Constructor Details

#initialize(library, properties) ⇒ Playlist

Returns a new instance of Playlist.



3
4
5
6
# File 'lib/itunes/playlist.rb', line 3

def initialize(library, properties)
  @library    = library
  @properties = properties
end

Instance Method Details

#[](key) ⇒ Object



8
9
10
# File 'lib/itunes/playlist.rb', line 8

def [](key)
  @properties[key]
end

#inspectObject



29
30
31
# File 'lib/itunes/playlist.rb', line 29

def inspect
  "#<#{self.class.name} name=#{name.inspect} size=#{size}>"
end

#item_idsObject



16
17
18
# File 'lib/itunes/playlist.rb', line 16

def item_ids
  (self['Playlist Items'] || []).map { |t| t['Track ID'] }
end

#itemsObject Also known as: tracks



20
21
22
# File 'lib/itunes/playlist.rb', line 20

def items
  @items ||= item_ids.map { |id| @library.fetch_track(id) }
end

#nameObject



12
13
14
# File 'lib/itunes/playlist.rb', line 12

def name
  self['Name']
end

#sizeObject



25
26
27
# File 'lib/itunes/playlist.rb', line 25

def size
  item_ids.size
end