Class: ImportEverything::SqlInsertParser

Inherits:
Parser::ImpParsers show all
Defined in:
lib/import_everything/parsers/sql_parser.rb

Defined Under Namespace

Classes: LineParser

Instance Method Summary collapse

Methods inherited from Parser::ImpParsers

#line_parsers, #parsers

Methods inherited from Parser

#value_hashes

Instance Method Details

#get_insert_lines(lines) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/import_everything/parsers/sql_parser.rb', line 9

def get_insert_lines(lines)
  if lines.empty?
    []
  elsif LineParser.comment?(lines.first)
    get_insert_lines(lines[1..-1])
  elsif LineParser.valid_insert?(lines.first)
    [lines.first] + get_insert_lines(lines[1..-1])
  elsif lines.size >= 2 && LineParser.valid_insert?(lines[0..1].join(" "))
    [lines[0..1].join(" ")] + get_insert_lines(lines[2..-1])
  elsif lines.size >= 3 && LineParser.valid_insert?(lines[0..2].join(" "))
    [lines[0..2].join(" ")] + get_insert_lines(lines[2..-1])
  else
    get_insert_lines(lines[1..-1])
  end
end