Module: Importer::Parser

Defined in:
lib/importer/parser.rb,
lib/importer/parser/csv.rb,
lib/importer/parser/xml.rb,
lib/importer/parser/base.rb

Overview

Determines the parser needed to parse given file basing on file extension. Return Xml parser for .xml files, Csv parser for .csv file and so on.

Defined Under Namespace

Classes: Base, Csv, Xml

Class Method Summary collapse

Class Method Details

.get_klass(file) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/importer/parser.rb', line 7

def self.get_klass(file)
  extension = File.extname(file)[1..-1]

  if extension
    klass = extension.camelize

    if Importer::Parser.const_defined?(klass.to_sym)
      klass = "Importer::Parser::#{klass}".constantize
      return klass
    end
  end

  raise Importer::ParserNotFoundError.new("Can't find #{klass} parser.")
end