Class: MPD::Song
- Inherits:
-
Object
- Object
- MPD::Song
- Defined in:
- lib/ruby-mpd/song.rb
Overview
This class is a glorified Hash used to represent a song.
If the field doesn’t exist or isn’t set, nil will be returned
Instance Method Summary collapse
-
#==(another) ⇒ Object
Two songs are the same when they are the same file.
-
#initialize(options) ⇒ Song
constructor
A new instance of Song.
- #length ⇒ Object
- #method_missing(m, *a) ⇒ Object
Constructor Details
#initialize(options) ⇒ Song
Returns a new instance of Song.
7 8 9 10 |
# File 'lib/ruby-mpd/song.rb', line 7 def initialize() @data = {} @data.merge! end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *a) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ruby-mpd/song.rb', line 21 def method_missing(m, *a) key = m #.to_s if key =~ /=$/ @data[$`] = a[0] elsif a.empty? @data[key] else raise NoMethodError, "#{m}" end end |
Instance Method Details
#==(another) ⇒ Object
Two songs are the same when they are the same file.
13 14 15 |
# File 'lib/ruby-mpd/song.rb', line 13 def ==(another) self.file == another.file end |
#length ⇒ Object
17 18 19 |
# File 'lib/ruby-mpd/song.rb', line 17 def length return "#{(@data.time / 60)}:#{"%02d" % (@data.time % 60)}" end |