Sha256: 71f152c4c7c6cc8674ccd035d6fb2ebcd0d7b8b190cb5acef940bfd890a65de2

Contents?: true

Size: 756 Bytes

Versions: 1

Compression:

Stored size: 756 Bytes

Contents

require 'csv'

require 'simple_csv/version'
require 'simple_csv/base'
require 'simple_csv/reader'
require 'simple_csv/writer'

module SimpleCsv
  @converters_initialized = false

  def self.read(path, **options, &block)
    initialize_converters unless converters_initialized
    Reader.new path, options, &block
  end

  def self.generate(path, **options, &block)
    initialize_converters unless converters_initialized
    Writer.new path, options, &block
  end

  def self.initialize_converters
    CSV::Converters[:blank_to_nil] = ->(f) { f && f.empty? ? nil : f }
    CSV::Converters[:null_to_nil] = ->(f) { f && f == 'NULL' ? nil : f }
    @converters_initialized = true
  end

  def self.converters_initialized
    @converters_initialized
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
simple_csv-0.1.0 lib/simple_csv.rb