Class: ITunes::Library

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(properties) ⇒ Library

Returns a new instance of Library.



13
14
15
# File 'lib/itunes/library.rb', line 13

def initialize(properties)
  @properties = properties || {}
end

Class Method Details

.load(file) ⇒ Object



9
10
11
# File 'lib/itunes/library.rb', line 9

def self.load(file)
  new(Plist::parse_xml(file))
end

Instance Method Details

#[](key) ⇒ Object



17
18
19
# File 'lib/itunes/library.rb', line 17

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

#booksObject



45
46
47
# File 'lib/itunes/library.rb', line 45

def books
  find_playlist 'Books'
end

#fetch_track(id) ⇒ Object



53
54
55
# File 'lib/itunes/library.rb', line 53

def fetch_track(id)
  Track.new(self, track_ids[id.to_s])
end

#find_playlist(name) ⇒ Object



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

def find_playlist(name)
  playlists.detect { |p| p.name == name }
end

#inspectObject



65
66
67
# File 'lib/itunes/library.rb', line 65

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

#moviesObject



33
34
35
# File 'lib/itunes/library.rb', line 33

def movies
  find_playlist 'Movies'
end

#musicObject



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

def music
  find_playlist 'Music'
end

#playlistsObject



21
22
23
# File 'lib/itunes/library.rb', line 21

def playlists
  @playlists ||= self['Playlists'].map { |p| Playlist.new(self, p) }
end

#podcastsObject



41
42
43
# File 'lib/itunes/library.rb', line 41

def podcasts
  find_playlist 'Podcasts'
end

#sizeObject



61
62
63
# File 'lib/itunes/library.rb', line 61

def size
  track_ids.size
end

#track_idsObject



49
50
51
# File 'lib/itunes/library.rb', line 49

def track_ids
  self['Tracks']
end

#tracksObject



57
58
59
# File 'lib/itunes/library.rb', line 57

def tracks
  @tracks ||= self['Tracks'].values.map { |t| Track.new(self, t) }
end

#tv_showsObject



37
38
39
# File 'lib/itunes/library.rb', line 37

def tv_shows
  find_playlist 'TV Shows'
end