Class: Droonga::GroongaCommandConverter
- Inherits:
-
Object
- Object
- Droonga::GroongaCommandConverter
- Defined in:
- lib/groonga_command_converter.rb
Constant Summary collapse
- STATUS_OK =
200.freeze
Instance Method Summary collapse
- #convert(input, &block) ⇒ Object
-
#initialize(options = {}) ⇒ GroongaCommandConverter
constructor
A new instance of GroongaCommandConverter.
Constructor Details
#initialize(options = {}) ⇒ GroongaCommandConverter
Returns a new instance of GroongaCommandConverter.
26 27 28 29 30 31 |
# File 'lib/groonga_command_converter.rb', line 26 def initialize(={}) @options = @count = 0 @command_parser = Groonga::Command::Parser.new end |
Instance Method Details
#convert(input, &block) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/groonga_command_converter.rb', line 33 def convert(input, &block) @command_parser.on_command do |command| case command.name when "table_create" yield create_table_create_command(command) when "column_create" yield create_column_create_command(command) when "select" yield create_select_command(command) end end parsed_values = nil parsed_columns = nil @command_parser.on_load_start do |command| parsed_values = [] parsed_columns = nil end @command_parser.on_load_columns do |command, columns| parsed_columns = columns end @command_parser.on_load_value do |command, value| parsed_values << value end @command_parser.on_load_complete do |command| command[:columns] = parsed_columns.join(",") command[:values] = parsed_values.to_json split_load_command_to_add_commands(command, &block) end input.each_line do |line| @command_parser << line end @command_parser.finish end |