Class: DataSource

Inherits:
Object
  • Object
show all
Defined in:
lib/data_source.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table_name, input_path, csv_opts = {}, &block) ⇒ DataSource

Returns a new instance of DataSource.



8
9
10
11
12
# File 'lib/data_source.rb', line 8

def initialize table_name, input_path, csv_opts = {}, &block
  @table_name, @input_path = table_name, input_path
  @csv_opts = csv_opts ? csv_opts.dup : {}
  @block = block
end

Instance Attribute Details

#input_pathObject (readonly)

Returns the value of attribute input_path.



6
7
8
# File 'lib/data_source.rb', line 6

def input_path
  @input_path
end

#table_nameObject (readonly)

Returns the value of attribute table_name.



6
7
8
# File 'lib/data_source.rb', line 6

def table_name
  @table_name
end

Instance Method Details

#drop_tableObject



29
30
31
# File 'lib/data_source.rb', line 29

def drop_table
  conn.drop_table table_name
end

#importObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/data_source.rb', line 14

def import
  batch = []
  TableUtils::Progress.over csv do |row, bar|
    batch << common_columns.map{ |c| row[c] }
    if batch.count >= 1000 || bar.finished?
      model.import common_columns, batch, validate: false
      batch = []
    end
  end
end

#table_exists?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/data_source.rb', line 25

def table_exists?
  conn.table_exists? table_name
end