Class: MPD::Protocol::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/mpd/protocol/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, *arguments) ⇒ Command

Returns a new instance of Command.



16
17
18
19
# File 'lib/mpd/protocol/command.rb', line 16

def initialize (name, *arguments)
	@name      = name.to_sym
	@arguments = arguments.flatten.compact
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



14
15
16
# File 'lib/mpd/protocol/command.rb', line 14

def arguments
  @arguments
end

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'lib/mpd/protocol/command.rb', line 14

def name
  @name
end

Instance Method Details

#to_sObject



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
# File 'lib/mpd/protocol/command.rb', line 21

def to_s
	result = name.to_s

	unless arguments.empty?
		result << ' ' << arguments.map {|argument|
			if argument.is_a? Range
				if argument.end == -1
					"#{argument.begin}:"
				else
					"#{argument.begin}:#{argument.end + (argument.exclude_end? ? 0 : 1)}"
				end
			elsif argument == true || argument == false
				argument ? '1' : '0'
			else
				argument = argument.to_s

				if argument.include?(' ') || argument.include?('"')
					%{"#{argument.gsub '"', '\"'}"}
				else
					argument
				end
			end
		}.join(' ')
	end

	result
end