Sha256: f667f8d1adf2d1e68a84e931eed28ab67d90455bbede12f14ee896b8336aa60e
Contents?: true
Size: 1.7 KB
Versions: 3
Compression:
Stored size: 1.7 KB
Contents
module ETL #:nodoc: module Control #:nodoc: # A File source. class FileSource < Source # The number of lines to skip, default is 0 attr_accessor :skip_lines # Accessor for the underlying parser attr_accessor :parser # Initialize the source # # Configuration options: # * <tt>:parser</tt>: One of the following: a parser name as a String or symbol, a class which extends from Parser, # a Hash with :name and optionally an :options key. Whether or not the parser uses the options is dependent on # which parser is used. See the documentation for each parser for information on what options it accepts. # * <tt>:skip_lines<tt>: The number of lines to skip (defaults to 0) def initialize(control, configuration, definition) super configure end def to_s configuration[:file] end # Returns each row from the source def each @parser.each { |row| yield row } end private # Configure the source def configure case @configuration[:parser] when Class @parser = @configuration[:parser].new(self) when String, Symbol @parser = ETL::Parser::Parser.class_for_name(@configuration[:parser]).new(self) when Hash name = @configuration[:parser][:name] options = @configuration[:parser][:options] @parser = ETL::Parser::Parser.class_for_name(name).new(self, options) else raise ControlError, "Configuration option :parser must be a Class, String or Symbol" end @skip_lines = @configuration[:skip_lines] ||= 0 end end end end
Version data entries
3 entries across 3 versions & 1 rubygems