Class: HarerunParser::Command

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

Instance Method Summary collapse

Instance Method Details

#headers(input_file) ⇒ Object



33
34
35
36
37
# File 'lib/harerun_parser/command.rb', line 33

def headers(input_file )
  File.open(input_file, 'r') do |f|
    p HarerunParser::Parser.new(f).headers
  end
end

#normalize(input_file, output_file = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/harerun_parser/command.rb', line 8

def normalize(input_file, output_file=nil)
  File.open(input_file, 'r') do |f|
    harerun = HarerunParser::Parser.new(f)

    if output_file.nil?
      harerun.normalize do |day, place, header, value|
        puts "#{day},#{place},#{header},#{value}"
      end
    else
      csv = CSV.open(output_file, 'wb')
      harerun.normalize do |day, place, header, value|
        csv << [day, place, header, value]
      end
    end
  end
end

#places(input_file) ⇒ Object



26
27
28
29
30
# File 'lib/harerun_parser/command.rb', line 26

def places(input_file)
  File.open(input_file, 'r') do |f|
    p HarerunParser::Parser.new(f).places
  end
end