Sha256: 0cc8eb07f8690f4ec76363c3ebf922b0c3e9024dd40b6ebeffd8f1755dc75601

Contents?: true

Size: 650 Bytes

Versions: 5

Compression:

Stored size: 650 Bytes

Contents

# frozen_string_literal: true

module FileBuilders
  class CSVFileBuilder
    attr_reader :data, :file_name, :options

    def initialize(data, file_name, options)
      @data = data
      @file_name = file_name
      @options = options
    end

    def export_to_file
      titles_row = (options[:titles].join(';').concat(';').concat("\n") if options[:titles].size.positive?)

      data_without_options = data.map { |row| row[0...-1] }
      csv_data = data_without_options.map { |row| row.join(';').concat(';') }.join("\n")

      File.open(file_name, 'a') do |file|
        file << titles_row
        file << csv_data
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
tabled-1.2.1 lib/file_builders/csv_file_builder.rb
tabled-1.2.0 lib/file_builders/csv_file_builder.rb
tabled-1.1.0 lib/file_builders/csv_file_builder.rb
tabled-1.0.0 lib/file_builders/csv_file_builder.rb
tabled-0.0.6 lib/file_builders/csv_file_builder.rb