Class: DataKit::CSV::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/data_kit/csv/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Parser

Returns a new instance of Parser.



10
11
12
13
14
15
# File 'lib/data_kit/csv/parser.rb', line 10

def initialize(path)
  @path = path
  
  set_handle
  set_headers
end

Instance Attribute Details

#handleObject (readonly)

Returns the value of attribute handle.



7
8
9
# File 'lib/data_kit/csv/parser.rb', line 7

def handle
  @handle
end

#headersObject (readonly)

Returns the value of attribute headers.



8
9
10
# File 'lib/data_kit/csv/parser.rb', line 8

def headers
  @headers
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/data_kit/csv/parser.rb', line 6

def path
  @path
end

Instance Method Details

#each_row(&block) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/data_kit/csv/parser.rb', line 17

def each_row(&block)
  handle.rewind
  Rcsv.parse(handle, :header => :skip, :columns => columns, :row_as_hash => true) do |row|
    puts row.inspect
    yield row
  end
end