Sha256: 8780edead81102dcccb48aba5660c3fe5ca09e4cc6bc6d747a0186111ea18237

Contents?: true

Size: 933 Bytes

Versions: 12

Compression:

Stored size: 933 Bytes

Contents

module Remi
  module DataTarget
    class CsvFile
      include DataTarget

      def self.default_csv_options
        CSV::DEFAULT_OPTIONS.merge({
          headers: true,
          header_converters: Remi::FieldSymbolizers[:standard],
          col_sep: ',',
          encoding: 'UTF-8',
          quote_char: '"',
          row_sep: "\n"
        })
      end

      def initialize(path:, csv_options: {}, logger: Remi::Settings.logger)
        @path = path
        @csv_options = self.class.default_csv_options.merge(csv_options)
        @logger = logger
      end

      attr_reader   :path
      attr_reader   :csv_options

      def field_symbolizer
        self.class.default_csv_options[:header_converters]
      end

      def load
        return true if @loaded || df.size == 0

        @logger.info "Writing CSV file #{@path}"

        df.write_csv @path, @csv_options

        @loaded = true
      end

    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
remi-0.2.27 lib/remi/data_target/csv_file.rb
remi-0.2.26 lib/remi/data_target/csv_file.rb
remi-0.2.25 lib/remi/data_target/csv_file.rb
remi-0.2.24 lib/remi/data_target/csv_file.rb
remi-0.2.23 lib/remi/data_target/csv_file.rb
remi-0.2.22 lib/remi/data_target/csv_file.rb
remi-0.2.21 lib/remi/data_target/csv_file.rb
remi-0.2.20 lib/remi/data_target/csv_file.rb
remi-0.2.19 lib/remi/data_target/csv_file.rb
remi-0.2.18 lib/remi/data_target/csv_file.rb
remi-0.2.17 lib/remi/data_target/csv_file.rb
remi-0.2.16 lib/remi/data_target/csv_file.rb