Sha256: 1260926359edddbec2762be27d3fe9c5c573cc0478d0ff4a048e8ef71298000b
Contents?: true
Size: 1.31 KB
Versions: 4
Compression:
Stored size: 1.31 KB
Contents
module ETL module Parser class Parser include Enumerable class << self # Convert the name (string or symbol) to a parser class. # # Example: # <tt>class_for_name(:fixed_width)</tt> returns a FixedWidthParser class def class_for_name(name) ETL::Parser.const_get("#{name.to_s.classify}Parser") end end # The Source object for the data attr_reader :source # Options Hash for the parser attr_reader :options def initialize(source, options={}) @source = source @options = options || {} end # Convert the value to the specified type. # # Parameters: # * <tt>name</tt>: The name of the field # * <tt>value</tt>: The value # * <tt>type</tt>: The type name (:integer, :float, :string) def convert(name, value, type) case type when :integer value.to_i when :float value.to_f else value end end protected def file File.join(File.dirname(source.control.file), source.configuration[:file]) end def raise_with_info(error, message, file, line) raise error, "#{message} (line #{line} in #{file})" end end end end
Version data entries
4 entries across 4 versions & 1 rubygems