Sha256: a38dbbd5ae4f801970a63a15257c99f6cf09e6d1266e4f9cd8efbf0b8c44f2e1

Contents?: true

Size: 1.04 KB

Versions: 22

Compression:

Stored size: 1.04 KB

Contents

# This file allows us to choose the CSV library we want to use.

require 'csv'
# Using relevant core CSV library.
CSVLibrary = CSV

class << CSVLibrary
  # Is the library we're using FasterCSV?
  def fastercsv?
    not self.const_defined?(:Reader)
  end

  # Ensure that we can pass "mode" straight through the underlying IO object
  def foreach(path, **options, &block)
    return to_enum(__method__, path, options) unless block
    open(path, options.delete(:mode) || 'r', options) do |csv|
      csv.each(&block)
    end
  end

  def write_csv_to_string(data)
    self.generate do |csv|
      data.each { |line| csv << line }
    end
  end

  def write_csv_to_file(data, filepath, mode = 'w')
    self.open(filepath, mode) do |csv|
      data.each { |line| csv << line }
    end
  end

  def read_csv_from_file(filepath)
    self.read(filepath)
  end
end

# Forward port CSV::Cell, as it is sometimes
# serialised in YAML. :-(
class CSV::Cell < String
  def initialize(data = '', is_null = false)
    super(is_null ? '' : data)
  end

  def data
    to_s
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
ndr_import-9.0.2 lib/ndr_import/csv_library.rb
ndr_import-9.0.1 lib/ndr_import/csv_library.rb
ndr_import-9.0.0 lib/ndr_import/csv_library.rb
ndr_import-8.6.0 lib/ndr_import/csv_library.rb
ndr_import-8.5.2 lib/ndr_import/csv_library.rb
ndr_import-8.5.1 lib/ndr_import/csv_library.rb
ndr_import-8.5.0 lib/ndr_import/csv_library.rb
ndr_import-8.4.0 lib/ndr_import/csv_library.rb
ndr_import-8.3.0 lib/ndr_import/csv_library.rb
ndr_import-8.2.0 lib/ndr_import/csv_library.rb
ndr_import-8.1.0 lib/ndr_import/csv_library.rb
ndr_import-8.0.0 lib/ndr_import/csv_library.rb
ndr_import-7.0.0 lib/ndr_import/csv_library.rb
ndr_import-6.4.1 lib/ndr_import/csv_library.rb
ndr_import-6.4.0 lib/ndr_import/csv_library.rb
ndr_import-6.3.0 lib/ndr_import/csv_library.rb
ndr_import-6.2.0 lib/ndr_import/csv_library.rb
ndr_import-6.1.1 lib/ndr_import/csv_library.rb
ndr_import-6.1.0 lib/ndr_import/csv_library.rb
ndr_import-6.0.0 lib/ndr_import/csv_library.rb