Sha256: 65e0fd74b9098ece2476234bcdafb206958a123be251c93cf7a2d36c38632b50

Contents?: true

Size: 1.01 KB

Versions: 3

Compression:

Stored size: 1.01 KB

Contents

module ETL
  module Parser
    class Parser
      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
      
      attr_reader :source
      
      def initialize(source)
        @source = source
      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
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
activewarehouse-etl-0.1.0 lib/etl/parser/parser.rb
activewarehouse-etl-0.2.0 lib/etl/parser/parser.rb
activewarehouse-etl-0.3.0 lib/etl/parser/parser.rb