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
# File 'lib/data_kit/csv/parser.rb', line 10

def initialize(path)
  @path = path
  set_handle      
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



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/data_kit/csv/parser.rb', line 15

def each_row(&block)
  first = true
  handle.rewind
  
  ::CSV.parse(handle, converters: nil) do |row|
    if first == true
      first = false
      @headers = row
    else
      yield row
    end
  end
end