Class: Groonga::Command::Builder
- Inherits:
-
Object
- Object
- Groonga::Command::Builder
- Defined in:
- lib/groonga/command.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#command ⇒ Object
readonly
Returns the value of attribute command.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #build ⇒ Object
-
#initialize(command, arguments = {}) ⇒ Builder
constructor
A new instance of Builder.
Constructor Details
#initialize(command, arguments = {}) ⇒ Builder
Returns a new instance of Builder.
29 30 31 32 |
# File 'lib/groonga/command.rb', line 29 def initialize(command, arguments={}) @command = command @arguments = arguments end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
28 29 30 |
# File 'lib/groonga/command.rb', line 28 def arguments @arguments end |
#command ⇒ Object (readonly)
Returns the value of attribute command.
28 29 30 |
# File 'lib/groonga/command.rb', line 28 def command @command end |
Class Method Details
.escape_value(value) ⇒ Object
22 23 24 25 |
# File 'lib/groonga/command.rb', line 22 def escape_value(value) escaped_value = value.to_s.gsub(/"/, '\\"') "\"#{escaped_value}\"" end |
Instance Method Details
#[](key) ⇒ Object
34 35 36 |
# File 'lib/groonga/command.rb', line 34 def [](key) @arguments[key] end |
#[]=(key, value) ⇒ Object
38 39 40 |
# File 'lib/groonga/command.rb', line 38 def []=(key, value) @arguments[key] = value end |
#build ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/groonga/command.rb', line 42 def build query = "#{@command} " @arguments.each do |key, value| value = value.join(", ") if value.is_a?(::Array) escaped_value = self.class.escape_value(value) query << " --#{key} #{escaped_value}" end query end |