Created
November 26, 2013 12:37
-
-
Save pjaspers/7657648 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def convert_command(command, *args) | |
args.map! do |word| | |
if word.is_a?(TrueClass) || word.is_a?(FalseClass) | |
word ? '1' : '0' # convert bool to 1 or 0 | |
elsif word.is_a?(Range) | |
if word.end == -1 # negative means to end of range | |
"#{word.begin}:" | |
else | |
"#{word.begin}:#{word.end + (word.exclude_end? ? 0 : 1)}" | |
end | |
elsif word.is_a?(MPD::Song) | |
%Q["#{word.file}"] # escape filename | |
else | |
# escape any strings with space (wrap in double quotes) | |
word = word.to_s | |
# word.match(/\s|'/) ? %Q["#{word}"] : word | |
if word.empty? | |
word | |
else | |
%Q["#{word}"] | |
end | |
end | |
end | |
return [command, args].join(' ').strip | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment