Sha256: 30db7706f4c94de9b7dc4928c24962ee8019c5db0cc917eba92f5307c711b984

Contents?: true

Size: 517 Bytes

Versions: 12

Compression:

Stored size: 517 Bytes

Contents

# frozen_string_literal: true

require "csv"

module Spout
  module Helpers
    # Reads CSVs and handles conversion of characters into UTF-8 format.
    class CSVReader
      def self.read_csv(csv_file)
        File.open(csv_file, "r:iso-8859-1:utf-8") do |file|
          csv = CSV.new(file, headers: true, header_converters: ->(h) { h.to_s.downcase })
          while line = csv.shift # rubocop:disable Lint/AssignmentInCondition
            yield line.to_hash
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
spout-1.0.0 lib/spout/helpers/csv_reader.rb
spout-1.0.0.beta3 lib/spout/helpers/csv_reader.rb
spout-1.0.0.beta2 lib/spout/helpers/csv_reader.rb
spout-1.0.0.beta1 lib/spout/helpers/csv_reader.rb
spout-0.14.1 lib/spout/helpers/csv_reader.rb
spout-0.14.0 lib/spout/helpers/csv_reader.rb
spout-0.14.0.rc lib/spout/helpers/csv_reader.rb
spout-0.14.0.beta3 lib/spout/helpers/csv_reader.rb
spout-0.14.0.beta2 lib/spout/helpers/csv_reader.rb
spout-0.14.0.beta1 lib/spout/helpers/csv_reader.rb
spout-0.13.0 lib/spout/helpers/csv_reader.rb
spout-0.13.0.beta2 lib/spout/helpers/csv_reader.rb