class Reviewer::Command::String::Flags
Assembles tool flag settings into a single string or array
Attributes
flag_pairs[R]
Public Class Methods
new(flag_pairs)
click to toggle source
# File lib/reviewer/command/string/flags.rb, line 10 def initialize(flag_pairs) @flag_pairs = flag_pairs end
Public Instance Methods
to_a()
click to toggle source
# File lib/reviewer/command/string/flags.rb, line 18 def to_a flags = [] flag_pairs.each { |key, value| flags << flag(key, value) } flags end
to_s()
click to toggle source
# File lib/reviewer/command/string/flags.rb, line 14 def to_s to_a.join(' ') end
Private Instance Methods
flag(key, value)
click to toggle source
# File lib/reviewer/command/string/flags.rb, line 26 def flag(key, value) dash = key.to_s.size == 1 ? '-' : '--' value = needs_quotes?(value) ? "'#{value}'" : value "#{dash}#{key} #{value}".strip end
needs_quotes?(value)
click to toggle source
# File lib/reviewer/command/string/flags.rb, line 34 def needs_quotes?(value) value.is_a?(::String) && value.include?(' ') end