Class: DataLoader::Loader
- Inherits:
-
Object
- Object
- DataLoader::Loader
- Defined in:
- lib/data_loader/loader.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#default_ext ⇒ Object
Returns the value of attribute default_ext.
-
#folder ⇒ Object
Returns the value of attribute folder.
-
#inspect_rows ⇒ Object
Returns the value of attribute inspect_rows.
-
#log(text) ⇒ Object
Returns the value of attribute log.
-
#separator ⇒ Object
Returns the value of attribute separator.
-
#table_prefix ⇒ Object
Returns the value of attribute table_prefix.
Instance Method Summary collapse
- #clear_log ⇒ Object
-
#initialize(folder = '', separator = ',', table_prefix = 'load', connection = :root) {|_self| ... } ⇒ Loader
constructor
A new instance of Loader.
- #load(filename, table = nil) ⇒ Object
Constructor Details
#initialize(folder = '', separator = ',', table_prefix = 'load', connection = :root) {|_self| ... } ⇒ Loader
Returns a new instance of Loader.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/data_loader/loader.rb', line 28 def initialize(folder = '', separator = ',', table_prefix = 'load', connection = :root) @folder, @separator = folder, separator @table_prefix, @connection = table_prefix, connection @default_ext = 'csv' @inspect_rows = 10 @log = true yield(self) if block_given? @logfile = File.(File.join(@folder, 'data_loader.textile')) puts @logfile end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
26 27 28 |
# File 'lib/data_loader/loader.rb', line 26 def connection @connection end |
#default_ext ⇒ Object
Returns the value of attribute default_ext.
26 27 28 |
# File 'lib/data_loader/loader.rb', line 26 def default_ext @default_ext end |
#folder ⇒ Object
Returns the value of attribute folder.
26 27 28 |
# File 'lib/data_loader/loader.rb', line 26 def folder @folder end |
#inspect_rows ⇒ Object
Returns the value of attribute inspect_rows.
26 27 28 |
# File 'lib/data_loader/loader.rb', line 26 def inspect_rows @inspect_rows end |
#log(text) ⇒ Object
Returns the value of attribute log.
26 27 28 |
# File 'lib/data_loader/loader.rb', line 26 def log @log end |
#separator ⇒ Object
Returns the value of attribute separator.
26 27 28 |
# File 'lib/data_loader/loader.rb', line 26 def separator @separator end |
#table_prefix ⇒ Object
Returns the value of attribute table_prefix.
26 27 28 |
# File 'lib/data_loader/loader.rb', line 26 def table_prefix @table_prefix end |
Instance Method Details
#clear_log ⇒ Object
58 59 60 |
# File 'lib/data_loader/loader.rb', line 58 def clear_log FileUtils.remove(@logfile) if File.exist?(@logfile) end |
#load(filename, table = nil) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/data_loader/loader.rb', line 39 def load(filename, table = nil) filename = [filename, default_ext].join('.') if File.extname(filename).empty? full_file = File.(File.join(@folder, filename)) table = Migrator.derive_table_name(filename) if table.nil? table = [@table_prefix, table].join('_') unless @table_prefix.blank? columns = Inspector.inspect_file(full_file, @separator, @inspect_rows) log_columns(table, columns) Migrator.migrate(full_file, columns, table, @separator, @connection) table end |