Class: FileBuilders::CSVFileBuilder
- Inherits:
-
Object
- Object
- FileBuilders::CSVFileBuilder
- Defined in:
- lib/file_builders/csv_file_builder.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #export_to_file ⇒ Object
-
#initialize(data, file_name, options) ⇒ CSVFileBuilder
constructor
A new instance of CSVFileBuilder.
Constructor Details
#initialize(data, file_name, options) ⇒ CSVFileBuilder
Returns a new instance of CSVFileBuilder.
7 8 9 10 11 |
# File 'lib/file_builders/csv_file_builder.rb', line 7 def initialize(data, file_name, ) @data = data @file_name = file_name @options = end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/file_builders/csv_file_builder.rb', line 5 def data @data end |
#file_name ⇒ Object (readonly)
Returns the value of attribute file_name.
5 6 7 |
# File 'lib/file_builders/csv_file_builder.rb', line 5 def file_name @file_name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/file_builders/csv_file_builder.rb', line 5 def @options end |
Instance Method Details
#export_to_file ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/file_builders/csv_file_builder.rb', line 13 def export_to_file titles_row = ([:titles].join(';').concat(';').concat("\n") if [:titles].size.positive?) = data.map { |row| row[0...-1] } csv_data = .map { |row| row.join(';').concat(';') }.join("\n") File.open(file_name, 'a') do |file| file << titles_row file << csv_data end end |