Class: DataImp
- Inherits:
-
Object
- Object
- DataImp
- Extended by:
- ClassMethods, Dir, Finders, ImportMethods
- Defined in:
- lib/data_imp.rb,
lib/data_imp.rb,
lib/data_imp/version.rb
Overview
Dir[File.dirname(__FILE__) + ‘/data_imp/*.rb’].each {|file| require file }
Defined Under Namespace
Modules: ClassMethods, Dir, Finders, ImportMethods Classes: NoImporter, NoParser, Parser, Porter, Tds
Constant Summary collapse
- VERSION =
"0.3.0"
- Importer =
DataImp::Porter
Instance Attribute Summary collapse
-
#basename ⇒ Object
Returns the value of attribute basename.
-
#extname ⇒ Object
Returns the value of attribute extname.
-
#file ⇒ Object
Returns the value of attribute file.
-
#importer ⇒ Object
Returns the value of attribute importer.
-
#parser ⇒ Object
Returns the value of attribute parser.
Instance Method Summary collapse
- #import ⇒ Object
-
#initialize(file = nil, parser: nil, importer: nil) ⇒ DataImp
constructor
A new instance of DataImp.
- #show_progress(index) ⇒ Object
Methods included from Finders
extended, find_importer, find_parser, included
Methods included from Dir
data_dir, data_dir=, extended, root, root=
Methods included from ImportMethods
Constructor Details
#initialize(file = nil, parser: nil, importer: nil) ⇒ DataImp
Returns a new instance of DataImp.
20 21 22 23 24 25 26 27 |
# File 'lib/data_imp.rb', line 20 def initialize file = nil, parser: nil, importer: nil self.file = data_dir.join(file) extname = File.extname(file) self.basename ||= File.basename(file, extname) self.extname = extname = extname.downcase.sub('.','') self.importer = find_importer(importer || basename) # returns class self.parser = find_parser(parser || extname) # returns class end |
Instance Attribute Details
#basename ⇒ Object
Returns the value of attribute basename.
18 19 20 |
# File 'lib/data_imp.rb', line 18 def basename @basename end |
#extname ⇒ Object
Returns the value of attribute extname.
18 19 20 |
# File 'lib/data_imp.rb', line 18 def extname @extname end |
#file ⇒ Object
Returns the value of attribute file.
18 19 20 |
# File 'lib/data_imp.rb', line 18 def file @file end |
#importer ⇒ Object
Returns the value of attribute importer.
18 19 20 |
# File 'lib/data_imp.rb', line 18 def importer @importer end |
#parser ⇒ Object
Returns the value of attribute parser.
18 19 20 |
# File 'lib/data_imp.rb', line 18 def parser @parser end |
Instance Method Details
#import ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/data_imp.rb', line 29 def import puts "Importing #{basename} with #{importer}" importer.before_all_imports parser.new(file).process_file do |hash, index| porter = importer.new(hash,index) begin porter.before_import porter.import porter.after_import show_progress index rescue StandardError => e warn "#{basename}:#{index}:#{e.class.name}" porter.on_error e end end importer.after_all_imports puts end |
#show_progress(index) ⇒ Object
48 49 50 51 |
# File 'lib/data_imp.rb', line 48 def show_progress index puts if index % 10_000 == 0 print '.' if index % 100 == 0 end |