Class: Slcsp::SlcspParser

Inherits:
Object
  • Object
show all
Defined in:
lib/slcsp/slcsp_parser.rb

Overview

parses the csv with slcsp zips and yeild line by line for external use

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ SlcspParser

Returns a new instance of SlcspParser.



8
9
10
# File 'lib/slcsp/slcsp_parser.rb', line 8

def initialize(path)
  @path = path
end

Instance Method Details

#headers_lineObject



22
23
24
25
26
27
# File 'lib/slcsp/slcsp_parser.rb', line 22

def headers_line
  f = File.open(@path)
  headers = f.gets
  f.close
  headers
end

#parse_each(&block) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/slcsp/slcsp_parser.rb', line 12

def parse_each(&block)
  return unless block_given?

  File.open(@path) do |file|
    CSV.foreach(file, headers: true) do |row|
      block.call row
    end
  end
end