class Typedcsv

Constants

VERSION

Attributes

args[R]
blk[R]

Public Class Methods

foreach(*args, &blk) click to toggle source
# File lib/typedcsv.rb, line 8
def Typedcsv.foreach(*args, &blk)
  typedcsv = new(*args, &blk)
  if args.last.is_a?(Hash) and args.last[:headers]
    typedcsv.foreach_hash
  else
    typedcsv.foreach_array
  end
end
new(*args, &blk) click to toggle source
# File lib/typedcsv.rb, line 20
def initialize(*args, &blk)
  @args = args
  @blk = blk
end

Public Instance Methods

foreach_array() click to toggle source
# File lib/typedcsv.rb, line 35
def foreach_array
  headers = nil
  CSV.foreach(*args) do |row|
    unless headers
      headers = Headers.new(row)
      next
    end
    blk.call headers.parse_array(row)
  end
end
foreach_hash() click to toggle source
# File lib/typedcsv.rb, line 25
def foreach_hash
  headers = nil
  CSV.foreach(*args) do |row|
    unless headers
      headers = Headers.new(row.headers)
    end
    blk.call headers.parse_hash(row)
  end
end