Class: Remi::DataTarget::CsvFile
- Inherits:
-
Object
- Object
- Remi::DataTarget::CsvFile
- Includes:
- Remi::DataTarget
- Defined in:
- lib/remi/data_target/csv_file.rb
Instance Attribute Summary collapse
-
#csv_options ⇒ Object
readonly
Returns the value of attribute csv_options.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #field_symbolizer ⇒ Object
-
#initialize(path:, csv_options: {}, logger: Remi::Settings.logger) ⇒ CsvFile
constructor
A new instance of CsvFile.
- #load ⇒ Object
Methods included from Remi::DataSubject
Constructor Details
#initialize(path:, csv_options: {}, logger: Remi::Settings.logger) ⇒ CsvFile
Returns a new instance of CsvFile.
17 18 19 20 21 |
# File 'lib/remi/data_target/csv_file.rb', line 17 def initialize(path:, csv_options: {}, logger: Remi::Settings.logger) @path = path @csv_options = self.class..merge() @logger = logger end |
Instance Attribute Details
#csv_options ⇒ Object (readonly)
Returns the value of attribute csv_options.
24 25 26 |
# File 'lib/remi/data_target/csv_file.rb', line 24 def @csv_options end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
23 24 25 |
# File 'lib/remi/data_target/csv_file.rb', line 23 def path @path end |
Class Method Details
.default_csv_options ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/remi/data_target/csv_file.rb', line 6 def self. CSV::DEFAULT_OPTIONS.merge({ headers: true, header_converters: Remi::FieldSymbolizers[:standard], col_sep: ',', encoding: 'UTF-8', quote_char: '"', row_sep: "\n" }) end |
Instance Method Details
#field_symbolizer ⇒ Object
26 27 28 |
# File 'lib/remi/data_target/csv_file.rb', line 26 def field_symbolizer self.class.[:header_converters] end |
#load ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/remi/data_target/csv_file.rb', line 30 def load return true if @loaded || df.size == 0 @logger.info "Writing CSV file #{@path}" df.write_csv @path, @csv_options @loaded = true end |