Class: DataForge::File::CSV::CSVRecordFileWriter
- Inherits:
-
Object
- Object
- DataForge::File::CSV::CSVRecordFileWriter
- Defined in:
- lib/data_forge/file/csv/csv_record_file_writer.rb
Instance Attribute Summary collapse
-
#definition ⇒ Object
readonly
Returns the value of attribute definition.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(definition) ⇒ CSVRecordFileWriter
constructor
A new instance of CSVRecordFileWriter.
- #open ⇒ Object
- #write(record) ⇒ Object
Constructor Details
#initialize(definition) ⇒ CSVRecordFileWriter
Returns a new instance of CSVRecordFileWriter.
12 13 14 15 16 |
# File 'lib/data_forge/file/csv/csv_record_file_writer.rb', line 12 def initialize(definition) @definition = definition @name = definition.name @fields = definition.field_names end |
Instance Attribute Details
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
8 9 10 |
# File 'lib/data_forge/file/csv/csv_record_file_writer.rb', line 8 def definition @definition end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
8 9 10 |
# File 'lib/data_forge/file/csv/csv_record_file_writer.rb', line 8 def fields @fields end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/data_forge/file/csv/csv_record_file_writer.rb', line 8 def name @name end |
Instance Method Details
#close ⇒ Object
27 28 29 30 |
# File 'lib/data_forge/file/csv/csv_record_file_writer.rb', line 27 def close @csv_file.close FileUtils.move @tempfile_name, definition.file_name end |
#open ⇒ Object
20 21 22 23 |
# File 'lib/data_forge/file/csv/csv_record_file_writer.rb', line 20 def open @tempfile_name = tempfile_name @csv_file = ::CSV.open @tempfile_name, "w", end |
#write(record) ⇒ Object
34 35 36 |
# File 'lib/data_forge/file/csv/csv_record_file_writer.rb', line 34 def write(record) @csv_file << fields.map { |field| record[field] } end |