Class: Net::DAAP::Song
- Inherits:
-
Object
- Object
- Net::DAAP::Song
- Includes:
- Comparable
- Defined in:
- lib/net/daap/song.rb
Overview
This class contains song information returned from the DAAP server.
Instance Attribute Summary collapse
-
#album ⇒ Object
readonly
Returns the value of attribute album.
-
#artist ⇒ Object
readonly
Returns the value of attribute artist.
-
#file ⇒ Object
Returns the value of attribute file.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
(also: #to_s)
readonly
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#persistentid ⇒ Object
readonly
Returns the value of attribute persistentid.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#get(&block) ⇒ Object
Fetches the song data from the DAAP server and returns it.
-
#initialize(args) ⇒ Song
constructor
A new instance of Song.
- #save(basedir = nil) ⇒ Object
Constructor Details
#initialize(args) ⇒ Song
Returns a new instance of Song.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/net/daap/song.rb', line 13 def initialize(args) @size = args['daap.songsize'] @album = args[:album] @name = args['dmap.itemname'] #@artist = args['daap.songartist'] @artist = args[:artist] @format = args['daap.songformat'] @persistentid = args['dmap.persistentid'] @id = args['dmap.itemid'] @daap = args[:daap] @db = args[:db] @path = [@artist.name, @album.name].collect { |name| name.gsub(File::SEPARATOR, '_') unless name.nil? }.join(File::SEPARATOR) @file = "#{@name.gsub(File::SEPARATOR, '_')}.#{@format}" end |
Instance Attribute Details
#album ⇒ Object (readonly)
Returns the value of attribute album.
8 9 10 |
# File 'lib/net/daap/song.rb', line 8 def album @album end |
#artist ⇒ Object (readonly)
Returns the value of attribute artist.
8 9 10 |
# File 'lib/net/daap/song.rb', line 8 def artist @artist end |
#file ⇒ Object
Returns the value of attribute file.
9 10 11 |
# File 'lib/net/daap/song.rb', line 9 def file @file end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
8 9 10 |
# File 'lib/net/daap/song.rb', line 8 def format @format end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
8 9 10 |
# File 'lib/net/daap/song.rb', line 8 def id @id end |
#name ⇒ Object (readonly) Also known as: to_s
Returns the value of attribute name.
8 9 10 |
# File 'lib/net/daap/song.rb', line 8 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
9 10 11 |
# File 'lib/net/daap/song.rb', line 9 def path @path end |
#persistentid ⇒ Object (readonly)
Returns the value of attribute persistentid.
8 9 10 |
# File 'lib/net/daap/song.rb', line 8 def persistentid @persistentid end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
8 9 10 |
# File 'lib/net/daap/song.rb', line 8 def size @size end |
Instance Method Details
#<=>(other) ⇒ Object
48 49 50 |
# File 'lib/net/daap/song.rb', line 48 def <=>(other) name <=> other.name end |
#get(&block) ⇒ Object
Fetches the song data from the DAAP server and returns it.
31 32 33 34 |
# File 'lib/net/daap/song.rb', line 31 def get(&block) filename = "#{@id}.#{@format}" @daap.get_song("databases/#{@db.id}/items/#{filename}", &block) end |
#save(basedir = nil) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/net/daap/song.rb', line 36 def save(basedir = nil) path = "#{basedir}#{File::SEPARATOR}#{@path}" FileUtils::mkdir_p(path) filename = "#{path}#{File::SEPARATOR}#{@file}" File.open(filename, "wb") { |file| get do |str| file.write str end } @daap.log.debug("Saved #{filename}") if @daap.log end |