Class: ImportEverything::DetermineType
- Includes:
- FromHash
- Defined in:
- lib/import_everything/determine_type.rb
Defined Under Namespace
Modules: Include
Class Method Summary collapse
Instance Method Summary collapse
-
#ext ⇒ String
Get the file extension.
- #method_missing(sym, *args, &b) ⇒ Object
-
#parser ⇒ Object
Creates the parser.
-
#parser_class ⇒ Object
Determines what parser class should be used for this file.
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
Instance Method Details
#ext ⇒ String
Get the file extension
18 |
# File 'lib/import_everything/determine_type.rb', line 18 fattr(:ext) { filename.split(".").last.downcase } |
#parser ⇒ Object
Creates the parser
44 45 46 |
# File 'lib/import_everything/determine_type.rb', line 44 def parser parser_class.new(parser_ops) end |
#parser_class ⇒ Object
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 |