Class: ImportEverything::DetermineType

Inherits:
Object
  • Object
show all
Includes:
FromHash
Defined in:
lib/import_everything/determine_type.rb

Defined Under Namespace

Modules: Include

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &b) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/import_everything/determine_type.rb', line 20

def method_missing(sym,*args,&b)
  if sym.to_s[-1..-1] == '='
    self.addl_ops[sym.to_s[0..-2]] = args.first
  else
    super
  end
end

Class Method Details

.get_filename(file) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/import_everything/determine_type.rb', line 4

def self.get_filename(file)
  if file.kind_of?(String)
    ''
  else
    file.first_responding(:original_filename, :filename, :path, :name)
  end
end

Instance Method Details

#extString

Get the file extension

Returns:



18
# File 'lib/import_everything/determine_type.rb', line 18

fattr(:ext) { filename.split(".").last.downcase }

#parserObject

Creates the parser



44
45
46
# File 'lib/import_everything/determine_type.rb', line 44

def parser
  parser_class.new(parser_ops)
end

#parser_classObject

Determines what parser class should be used for this file



33
34
35
36
37
38
39
40
41
# File 'lib/import_everything/determine_type.rb', line 33

def parser_class
  h = {'sqlite' => SqliteParser, 'sqlite3' => SqliteParser, 'csv' => CsvParser, 'xml' => XmlParser, 'sql' => SqlInsertParser, 'dmp' => SqlInsertParser, 'html' => TableParser}
  h = h.merge('yaml' => YamlParser, 'yml' => YamlParser)
  h[ext].tap { |x| return x if x }
  h.each do |k,klass|
    return klass if ext =~ /^#{k}\d\d/
  end
  raise "no parser found for #{ext}"
end