Class: ETL::Control::FileSource
Overview
A File source.
Instance Attribute Summary (collapse)
-
- (Object) file
The source file.
-
- (Object) parser
Accessor for the underlying parser.
-
- (Object) skip_lines
The number of lines to skip, default is 0.
Attributes inherited from Source
#configuration, #control, #definition, #local_base, #store_locally
Instance Method Summary (collapse)
-
- (Object) each
Returns each row from the source.
-
- (FileSource) initialize(control, configuration, definition)
constructor
Initialize the source.
-
- (Object) local_directory
Get the local storage directory.
- - (Object) order
-
- (Object) to_s
Get a String identifier for the source.
Methods inherited from Source
class_for_name, #errors, #last_local_file, #last_local_file_trigger, #local_file, #local_file_trigger, #read_locally, #timestamp
Constructor Details
- (FileSource) initialize(control, configuration, definition)
Initialize the source
Configuration options:
-
:file: The source file
-
:parser: 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.
-
:skip_lines: The number of lines to skip (defaults to 0)
-
:store_locally: Set to false to not store a copy of the source data locally for archival
26 27 28 29 |
# File 'lib/etl/control/source/file_source.rb', line 26 def initialize(control, configuration, definition) super configure end |
Instance Attribute Details
- (Object) file
The source file
12 13 14 |
# File 'lib/etl/control/source/file_source.rb', line 12 def file @file end |
- (Object) parser
Accessor for the underlying parser
9 10 11 |
# File 'lib/etl/control/source/file_source.rb', line 9 def parser @parser end |
- (Object) skip_lines
The number of lines to skip, default is 0
6 7 8 |
# File 'lib/etl/control/source/file_source.rb', line 6 def skip_lines @skip_lines end |
Instance Method Details
- (Object) each
Returns each row from the source
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/etl/control/source/file_source.rb', line 42 def each count = 0 copy_sources if @store_locally @parser.each do |row| if ETL::Engine.offset && count < ETL::Engine.offset count += 1 else row = ETL::Row[row] row.source = self yield row end end end |
- (Object) local_directory
Get the local storage directory
37 38 39 |
# File 'lib/etl/control/source/file_source.rb', line 37 def local_directory File.join(local_base, File.basename(file, File.extname(file))) end |
- (Object) order
56 57 58 |
# File 'lib/etl/control/source/file_source.rb', line 56 def order @parser.fields.collect {|field| field.name} end |
- (Object) to_s
Get a String identifier for the source
32 33 34 |
# File 'lib/etl/control/source/file_source.rb', line 32 def to_s file end |