Class: MPD::Controller::Database::Song
- Inherits:
-
Object
- Object
- MPD::Controller::Database::Song
- Defined in:
- lib/mpd/controller/database.rb
Defined Under Namespace
Classes: Tags
Instance Attribute Summary collapse
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#duration ⇒ Object
Returns the value of attribute duration.
-
#file ⇒ Object
(also: #uri)
Returns the value of attribute file.
-
#position ⇒ Object
Returns the value of attribute position.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Class Method Summary collapse
Instance Method Summary collapse
- #add ⇒ Object
-
#initialize(controller = nil) ⇒ Song
constructor
A new instance of Song.
- #inspect ⇒ Object
- #method_missing(id) ⇒ Object
- #respond_to_missing(id, include_private = false) ⇒ Object
Constructor Details
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(id) ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/mpd/controller/database.rb', line 88 def method_missing (id, *) if @tags.respond_to? id return @tags.__send__ id end super end |
Instance Attribute Details
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
72 73 74 |
# File 'lib/mpd/controller/database.rb', line 72 def controller @controller end |
#duration ⇒ Object
Returns the value of attribute duration.
73 74 75 |
# File 'lib/mpd/controller/database.rb', line 73 def duration @duration end |
#file ⇒ Object Also known as: uri
Returns the value of attribute file.
73 74 75 |
# File 'lib/mpd/controller/database.rb', line 73 def file @file end |
#position ⇒ Object
Returns the value of attribute position.
73 74 75 |
# File 'lib/mpd/controller/database.rb', line 73 def position @position end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
72 73 74 |
# File 'lib/mpd/controller/database.rb', line 72 def @tags end |
Class Method Details
.from_data(data, controller = nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/mpd/controller/database.rb', line 17 def self.from_data (data, controller = nil) if data.count { |name, _| name == :file } > 1 result = [] to_read = nil data.each {|name, value| if name == :file if to_read result << Song.from_data(to_read, controller) end to_read = [[name, value]] else to_read << [name, value] end } result << Song.from_data(to_read, controller) result else song = new(controller) data.each {|name, value| case name when :file then song.file = value when :Pos then song.position = value when :Time then song.duration = value when :Track then song..track = value when :Title then song..title = value when :Artist then song..artist = value when :Album then song..album = value when :Genre then song..genre = value when :Date then song..date = value when :Composer then song..composer = value when :Performer then song..performer = value when :Disc then song..disc = value when :MUSICBRAINZ_TRACKID then song..id = value end } song end end |
.from_uri(uri, controller = nil) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/mpd/controller/database.rb', line 62 def self.from_uri (uri, controller = nil) if controller from_data(controller.do_and_raise_if_needed(:listallinfo, uri), controller) else Song.new.tap {|song| song.file = uri } end end |
Instance Method Details
#add ⇒ Object
80 81 82 |
# File 'lib/mpd/controller/database.rb', line 80 def add raise 'no controller, cannot add to playlist' unless controller end |
#inspect ⇒ Object
98 99 100 |
# File 'lib/mpd/controller/database.rb', line 98 def inspect "#<#{self.class.name}: #{file.inspect}>" end |
#respond_to_missing(id, include_private = false) ⇒ Object
84 85 86 |
# File 'lib/mpd/controller/database.rb', line 84 def respond_to_missing (id, include_private = false) @tags.respond_to?(id, include_private) end |