Class: Grn2Drn::SchemaConverter

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

Defined Under Namespace

Classes: Column, Schema, Table, UnknownTable

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ SchemaConverter

Returns a new instance of SchemaConverter.



30
31
32
# File 'lib/grn2drn/schema-converter.rb', line 30

def initialize(options={})
  @options = options
end

Instance Method Details

#convert(input) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/grn2drn/schema-converter.rb', line 34

def convert(input)
  schema = Schema.new

  command_parser = Groonga::Command::Parser.new
  command_parser.on_command do |command|
    case command.name
    when "table_create"
      schema.on_table_create_command(command)
    when "column_create"
      schema.on_column_create_command(command)
    end
  end

  command_parser.on_load_value do |command, value|
    command.original_source.clear
  end

  input.each_line do |line|
    command_parser << line.force_encoding("UTF-8")
  end
  command_parser.finish

  schema.to_droonga_schema
end