class Athena::Formats::PGSQL
Private Instance Methods
init_in(*)
click to toggle source
Calls superclass method
Athena::Formats::Base#init_in
# File lib/athena/formats/sql.rb 113 def init_in(*) 114 @__record_element_ok__ = [String, nil] 115 super 116 end
parse(input, &block)
click to toggle source
# File lib/athena/formats/sql.rb 77 def parse(input, &block) 78 columns, table, num = Hash.new { |h, k| h[k] = [] }, nil, 0 79 80 input.each { |line| 81 case line = line.chomp 82 when /\ACOPY\s+(\S+)\s+\((.+?)\)\s+FROM\s+stdin;\z/i 83 columns[table = $1] = $2.split(/\s*,\s*/) 84 when /\A\\\.\z/ 85 table = nil 86 else 87 next unless table 88 89 cols = columns[table] 90 next if cols.empty? 91 92 Athena::Record.new(nil, block) { |record| 93 line.split(/\t/).each_with_index { |value, index| 94 column = cols[index] or next 95 96 if column == record_element 97 record.instance_variable_set(:@id, value) 98 end 99 100 record.update(column, value, config[column]) 101 } 102 } 103 104 num += 1 105 end 106 } 107 108 num 109 end