Class: Alf::Reader::CSV

Inherits:
Alf::Reader show all
Includes:
Support::CSVUtils
Defined in:
lib/alf/reader/csv.rb

Overview

Implements Alf::Reader contract for reading CSV files.

Constant Summary

Constants included from Support::CSVUtils

Support::CSVUtils::DEFAULT_OPTIONS

Constants inherited from Alf::Reader

DEFAULT_OPTIONS

Instance Attribute Summary

Attributes inherited from Alf::Reader

#input, #options, #path

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Alf::Reader

by_mime_type, coerce, #initialize, reader, register, #to_s

Methods included from Support::Registry

#listen, #listeners, #register, #registered

Constructor Details

This class inherits a constructor from Alf::Reader

Class Method Details

.mime_typeObject


9
10
11
# File 'lib/alf/reader/csv.rb', line 9

def self.mime_type
  "text/csv"
end

Instance Method Details

#eachObject


13
14
15
16
17
18
19
20
21
22
23
# File 'lib/alf/reader/csv.rb', line 13

def each
  return to_enum unless block_given?
  with_input_io do |io|
    block = Proc.new{|row|
      next if row.header_row?
      yield(::Alf::Support.symbolize_keys(row.to_hash))
    }
    csv_input = io.is_a?(StringIO) ? io.string : io
    get_csv(csv_input, options).each(&block)
  end
end