Class: ITunes::Library
- Inherits:
-
Object
- Object
- ITunes::Library
- Defined in:
- lib/itunes/library.rb
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #books ⇒ Object
- #fetch_track(id) ⇒ Object
- #find_playlist(name) ⇒ Object
-
#initialize(properties) ⇒ Library
constructor
A new instance of Library.
- #inspect ⇒ Object
- #movies ⇒ Object
- #music ⇒ Object
- #playlists ⇒ Object
- #podcasts ⇒ Object
- #size ⇒ Object
- #track_ids ⇒ Object
- #tracks ⇒ Object
- #tv_shows ⇒ Object
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 |
#books ⇒ Object
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 |
#inspect ⇒ Object
65 66 67 |
# File 'lib/itunes/library.rb', line 65 def inspect "#<#{self.class.name} size=#{size}>" end |
#movies ⇒ Object
33 34 35 |
# File 'lib/itunes/library.rb', line 33 def movies find_playlist 'Movies' end |
#music ⇒ Object
29 30 31 |
# File 'lib/itunes/library.rb', line 29 def music find_playlist 'Music' end |
#playlists ⇒ Object
21 22 23 |
# File 'lib/itunes/library.rb', line 21 def playlists @playlists ||= self['Playlists'].map { |p| Playlist.new(self, p) } end |
#podcasts ⇒ Object
41 42 43 |
# File 'lib/itunes/library.rb', line 41 def podcasts find_playlist 'Podcasts' end |
#size ⇒ Object
61 62 63 |
# File 'lib/itunes/library.rb', line 61 def size track_ids.size end |
#track_ids ⇒ Object
49 50 51 |
# File 'lib/itunes/library.rb', line 49 def track_ids self['Tracks'] end |
#tracks ⇒ Object
57 58 59 |
# File 'lib/itunes/library.rb', line 57 def tracks @tracks ||= self['Tracks'].values.map { |t| Track.new(self, t) } end |
#tv_shows ⇒ Object
37 38 39 |
# File 'lib/itunes/library.rb', line 37 def tv_shows find_playlist 'TV Shows' end |