Class: Groonga::Command::Format::Command
- Inherits:
-
Object
- Object
- Groonga::Command::Format::Command
- Defined in:
- lib/groonga/command/format/command.rb
Class Method Summary collapse
Instance Method Summary collapse
- #command_line ⇒ Object
-
#initialize(name, arguments) ⇒ Command
constructor
A new instance of Command.
Constructor Details
#initialize(name, arguments) ⇒ Command
Returns a new instance of Command.
40 41 42 43 |
# File 'lib/groonga/command/format/command.rb', line 40 def initialize(name, arguments) @name = name @arguments = arguments end |
Class Method Details
.escape_value(value) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/groonga/command/format/command.rb', line 26 def escape_value(value) escaped_value = value.gsub(/[\n"\\]/) do special_character = $MATCH case special_character when "\n" "\\n" else "\\#{special_character}" end end "\"#{escaped_value}\"" end |
Instance Method Details
#command_line ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/groonga/command/format/command.rb', line 45 def command_line components = [@name] sorted_arguments = @arguments.sort_by do |name, _| name.to_s end sorted_arguments.each do |name, value| components << "--#{name}" components << self.class.escape_value(value) end components.join(" ") end |