class DataImp

Dir[File.dirname(__FILE__) + '/data_imp/*.rb'].each {|file| require file }

Constants

Importer
VERSION

Attributes

basename[RW]
extname[RW]
file[RW]
importer[RW]
parser[RW]

Public Class Methods

new(file = nil, parser: nil, importer: nil) click to toggle source
# 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

Public Instance Methods

import() click to toggle source
# 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) click to toggle source
# File lib/data_imp.rb, line 48
def show_progress index
  puts if index % 10_000 == 0
  print '.' if index % 100 == 0
end