Class: MPD::Controller::Database::Song

Inherits:
Object
  • Object
show all
Defined in:
lib/mpd/controller/database.rb

Defined Under Namespace

Classes: Tags

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller = nil) ⇒ Song

Returns a new instance of Song.



75
76
77
78
# File 'lib/mpd/controller/database.rb', line 75

def initialize (controller = nil)
	@controller = controller
	@tags       = Tags.new
end

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

#controllerObject (readonly)

Returns the value of attribute controller.



72
73
74
# File 'lib/mpd/controller/database.rb', line 72

def controller
  @controller
end

#durationObject

Returns the value of attribute duration.



73
74
75
# File 'lib/mpd/controller/database.rb', line 73

def duration
  @duration
end

#fileObject 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

#positionObject

Returns the value of attribute position.



73
74
75
# File 'lib/mpd/controller/database.rb', line 73

def position
  @position
end

#tagsObject (readonly)

Returns the value of attribute tags.



72
73
74
# File 'lib/mpd/controller/database.rb', line 72

def tags
  @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.tags.track     = value
			when :Title               then song.tags.title     = value
			when :Artist              then song.tags.artist    = value
			when :Album               then song.tags.album     = value
			when :Genre               then song.tags.genre     = value
			when :Date                then song.tags.date      = value
			when :Composer            then song.tags.composer  = value
			when :Performer           then song.tags.performer = value
			when :Disc                then song.tags.disc      = value
			when :MUSICBRAINZ_TRACKID then song.tags.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

#addObject



80
81
82
# File 'lib/mpd/controller/database.rb', line 80

def add
	raise 'no controller, cannot add to playlist' unless controller
end

#inspectObject



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