Class: Remi::Encoder::CsvFile
- Inherits:
-
Remi::Encoder
- Object
- Remi::Encoder
- Remi::Encoder::CsvFile
- Includes:
- DataSubject::CsvFile
- Defined in:
- lib/remi/data_subjects/csv_file.rb
Overview
CsvFile Encoder
Instance Attribute Summary collapse
-
#csv_options ⇒ Hash
readonly
Csv options hash.
Attributes inherited from Remi::Encoder
#context, #field_symbolizer, #fields, #logger
Instance Method Summary collapse
-
#encode(dataframe) ⇒ Object
Converts the dataframe to a CSV file stored in the local work directory.
-
#initialize(*args, **kargs, &block) ⇒ CsvFile
constructor
A new instance of CsvFile.
Constructor Details
#initialize(*args, **kargs, &block) ⇒ CsvFile
Returns a new instance of CsvFile.
151 152 153 154 |
# File 'lib/remi/data_subjects/csv_file.rb', line 151 def initialize(*args, **kargs, &block) super init_csv_file_encoder(*args, **kargs, &block) end |
Instance Attribute Details
#csv_options ⇒ Hash (readonly)
Returns Csv options hash.
159 160 161 |
# File 'lib/remi/data_subjects/csv_file.rb', line 159 def @csv_options end |
Instance Method Details
#encode(dataframe) ⇒ Object
Converts the dataframe to a CSV file stored in the local work directory. If labels are present write the CSV file with those headers but maintain the structure of the original dataframe
167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/remi/data_subjects/csv_file.rb', line 167 def encode(dataframe) logger.info "Writing CSV file to temporary location #{@working_file}" label_columns = self.fields.reduce({}) { |h, (k, v)| if v[:label] h[k] = v[:label].to_sym end h } dataframe.rename_vectors label_columns dataframe.write_csv @working_file, @csv_options @working_file end |