Class: Grn2Drn::CommandConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/grn2drn/command-converter.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ CommandConverter

Returns a new instance of CommandConverter.



26
27
28
29
30
31
# File 'lib/grn2drn/command-converter.rb', line 26

def initialize(options={})
  @options = 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
# File 'lib/grn2drn/command-converter.rb', line 33

def convert(input, &block)
  @command_parser.on_command do |command|
    unless command.name == "load"
      yield create_message(command.name, command_to_body(command))
    end
  end

  parsed_columns = nil
  @command_parser.on_load_columns do |command, columns|
    parsed_columns = columns
  end
  @command_parser.on_load_value do |command, value|
    yield create_add_command(command, parsed_columns, value)
    command.original_source.clear
  end

  input.each_line do |line|
    @command_parser << line
  end
  @command_parser.finish
end