Sha256: 5277274f1b6f5102593c685724d982ebcc0d635f51a5c9ef3e38ac596d6d6230

Contents?: true

Size: 1.18 KB

Versions: 9

Compression:

Stored size: 1.18 KB

Contents

module ETL #:nodoc:
  module Parser #:nodoc:
    # Base parser class. Implementation classes must extend this class and implement
    # the each method. The each method should return each row of the source data as 
    # a Hash.
    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
      
      protected
      def file
        path = Pathname.new(source.configuration[:file])
        path = path.absolute? ? path : Pathname.new(File.dirname(source.control.file)) + path
        path
      end
      
      def raise_with_info(error, message, file, line)
        raise error, "#{message} (line #{line} in #{file})"
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
activewarehouse-etl-0.7.0 lib/etl/parser/parser.rb
activewarehouse-etl-0.7.1 lib/etl/parser/parser.rb
activewarehouse-etl-0.7.2 lib/etl/parser/parser.rb
activewarehouse-etl-0.8.0 lib/etl/parser/parser.rb
activewarehouse-etl-0.8.1 lib/etl/parser/parser.rb
activewarehouse-etl-0.8.2 lib/etl/parser/parser.rb
activewarehouse-etl-0.8.3 lib/etl/parser/parser.rb
activewarehouse-etl-0.8.4 lib/etl/parser/parser.rb
activewarehouse-etl-0.9.0 lib/etl/parser/parser.rb