Class: MPD::Protocol::Command
- Inherits:
-
Object
- Object
- MPD::Protocol::Command
- Defined in:
- lib/mpd/protocol/command.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name, *arguments) ⇒ Command
constructor
A new instance of Command.
- #to_s ⇒ Object
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
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
14 15 16 |
# File 'lib/mpd/protocol/command.rb', line 14 def arguments @arguments end |
#name ⇒ Object (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_s ⇒ Object
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 |