Class: HarerunParser::Parser

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

Constant Summary collapse

ENCODING =
"Shift_JIS:UTF-8"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ Parser

Returns a new instance of Parser.



9
10
11
12
# File 'lib/harerun_parser/parser.rb', line 9

def initialize(io)
  io.set_encoding(ENCODING)
  @data_lines = separate_headers(CSV(io).readlines)
end

Instance Attribute Details

#data_linesObject (readonly)

Returns the value of attribute data_lines.



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

def data_lines
  @data_lines
end

#headersObject (readonly)

Returns the value of attribute headers.



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

def headers
  @headers
end

#placesObject (readonly)

Returns the value of attribute places.



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

def places
  @places
end

Instance Method Details

#normalizeObject



14
15
16
17
18
19
20
21
# File 'lib/harerun_parser/parser.rb', line 14

def normalize
  @data_lines.each do |l|
    day = l.shift
    @places_line[1, @places_line.size - 1].zip(@headers, l).each do |place, header, value|
      yield(day, place, header, value) unless value.nil?
    end
  end
end

#uniq_headersObject



23
24
25
# File 'lib/harerun_parser/parser.rb', line 23

def uniq_headers
  headers.uniq
end