Class: Fias::Import::Copy

Inherits:
Object
  • Object
show all
Defined in:
lib/fias/import/copy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(db, table_name, dbf, types = {}) ⇒ Copy

Returns a new instance of Copy.



6
7
8
9
10
11
12
13
# File 'lib/fias/import/copy.rb', line 6

def initialize(db, table_name, dbf, types = {})
  @db = db
  @table_name = table_name.to_sym
  @dbf = dbf
  @encoder = PgDataEncoder::EncodeForCopy.new(
    column_types: map_types(types)
  )
end

Instance Attribute Details

#dbfObject (readonly)

Returns the value of attribute dbf.



4
5
6
# File 'lib/fias/import/copy.rb', line 4

def dbf
  @dbf
end

#table_nameObject (readonly)

Returns the value of attribute table_name.



4
5
6
# File 'lib/fias/import/copy.rb', line 4

def table_name
  @table_name
end

Instance Method Details

#copyObject



23
24
25
26
# File 'lib/fias/import/copy.rb', line 23

def copy
  prepare
  copy_into
end

#encodeObject



15
16
17
18
19
20
21
# File 'lib/fias/import/copy.rb', line 15

def encode
  @dbf.each do |record|
    line = record.to_a.map { |v| v == '' ? nil : v }
    @encoder.add(line)
    yield if block_given?
  end
end