Class: Iev::DbWriter
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
Instance Method Summary collapse
- #import_spreadsheet(file) ⇒ Object
-
#initialize(db) ⇒ DbWriter
constructor
A new instance of DbWriter.
Methods included from Cli::Ui
debug, info, progress, set_ui_tag, warn
Constructor Details
#initialize(db) ⇒ DbWriter
13 14 15 |
# File 'lib/iev/db_writer.rb', line 13 def initialize(db) @db = db end |
Instance Attribute Details
#db ⇒ Object (readonly)
Returns the value of attribute db.
11 12 13 |
# File 'lib/iev/db_writer.rb', line 11 def db @db end |
Instance Method Details
#import_spreadsheet(file) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/iev/db_writer.rb', line 17 def import_spreadsheet(file) Profiler.measure("xlsx-import") do workbook = open_workbook(file) row_enumerator = workbook.sheets.first.simple_rows.each title_row = row_enumerator.next symbolized_title_row = title_row.compact.transform_values(&:to_sym) create_table(symbolized_title_row.values) loop do row = row_enumerator.next next if row.empty? data = prepare_data(row, symbolized_title_row) display_progress(data) insert_data(data) end end end |