Skip to content

Instantly share code, notes, and snippets.

@pjaspers
Created November 26, 2013 12:37
Show Gist options
  • Save pjaspers/7657648 to your computer and use it in GitHub Desktop.
Save pjaspers/7657648 to your computer and use it in GitHub Desktop.
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