Sha256: b044d8ffd6e70284ca3ea0455fd38674401b82011e4af2921c77526bb0ff4d2e

Contents?: true

Size: 1.24 KB

Versions: 26

Compression:

Stored size: 1.24 KB

Contents

require 'ndr_support/safe_file'
require 'ndr_import/csv_library'
require 'ndr_import/helpers/file/delimited'
require_relative 'registry'

module NdrImport
  # This is one of a collection of file handlers that deal with individual formats of data.
  # They can be instantiated directly or via the factory method Registry.tables
  module File
    # This class is a delimited file handler that returns a single table.
    class Delimited < Base
      include Helpers::File::Delimited

      DELIMITED_COL_SEP = {
        'csv' => nil
      }
      def initialize(filename, format, options = {})
        super

        @options['col_sep'] ||= DELIMITED_COL_SEP[format]
      end

      private

      # Iterate through the file line by line, yielding each one in turn.
      def rows
        return enum_for(:rows) unless block_given?

        col_sep = @options['col_sep']
        liberal = @options['liberal_parsing'].presence

        delimited_rows(@filename, col_sep, liberal) { |row| yield row }
      end

      # Cache working encodings, so that resetting the enumerator
      # doesn't mean the need to recalculate this:
      def determine_encodings!(*)
        @encoding ||= super
      end
    end

    Registry.register(Delimited, 'csv', 'delimited')
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
ndr_import-11.2.1 lib/ndr_import/file/delimited.rb
ndr_import-11.2.0 lib/ndr_import/file/delimited.rb
ndr_import-11.1.0 lib/ndr_import/file/delimited.rb
ndr_import-11.0.2 lib/ndr_import/file/delimited.rb
ndr_import-11.0.1 lib/ndr_import/file/delimited.rb
ndr_import-11.0.0 lib/ndr_import/file/delimited.rb
ndr_import-10.3.0 lib/ndr_import/file/delimited.rb
ndr_import-10.2.0 lib/ndr_import/file/delimited.rb
ndr_import-10.1.3 lib/ndr_import/file/delimited.rb
ndr_import-10.1.2 lib/ndr_import/file/delimited.rb
ndr_import-10.1.1 lib/ndr_import/file/delimited.rb
ndr_import-10.1 lib/ndr_import/file/delimited.rb
ndr_import-10.0 lib/ndr_import/file/delimited.rb
ndr_import-9.1.0 lib/ndr_import/file/delimited.rb
ndr_import-9.0.3 lib/ndr_import/file/delimited.rb
ndr_import-9.0.2 lib/ndr_import/file/delimited.rb
ndr_import-9.0.1 lib/ndr_import/file/delimited.rb
ndr_import-9.0.0 lib/ndr_import/file/delimited.rb
ndr_import-8.6.0 lib/ndr_import/file/delimited.rb
ndr_import-8.5.2 lib/ndr_import/file/delimited.rb