Sha256: 4df7dd33ae32deb455133cbc1926c0acdc3831d98bb12f875abed30861247fe1

Contents?: true

Size: 728 Bytes

Versions: 5

Compression:

Stored size: 728 Bytes

Contents

module Alf
  module CSV
    #
    # Implements Alf::Reader contract for reading CSV files.
    #
    class Reader < Alf::Reader
      include CSV::Commons

      def each
        with_input_io do |io|
          block = Proc.new{|row|
            next if row.header_row?
            yield(symbolize_keys(row.to_hash))
          }
          case io
          when StringIO
            get_csv_class.parse(io.string, options, &block) 
          else
            get_csv(io).each(&block)
          end
        end
      end

      private

      def symbolize_keys(h)
        Hash[h.collect{|k,v| [k.to_sym,v] }]
      end

      Alf::Reader.register(:csv, [".csv"], self)
    end # class Reader
  end # module CSV
end # module Alf

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
alf-0.12.2 lib/alf-csv/alf/csv/reader.rb
alf-0.12.1 lib/alf-csv/alf/csv/reader.rb
alf-0.12.0 lib/alf-csv/alf/csv/reader.rb
alf-0.11.1 lib/alf-csv/alf/csv/reader.rb
alf-0.11.0 lib/alf-csv/alf/csv/reader.rb