Class: MPD::Song

Inherits:
Object
  • Object
show all
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

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(options)
  @data = {}
  @data.merge! options
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

#lengthObject



17
18
19
# File 'lib/ruby-mpd/song.rb', line 17

def length
  return "#{(@data.time / 60)}:#{"%02d" % (@data.time % 60)}"
end