Class: SportDb::CsvGoalParser

Inherits:
Object
  • Object
show all
Defined in:
lib/sportdb/structs/goal_parser_csv.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(txt) ⇒ CsvGoalParser

Returns a new instance of CsvGoalParser.



16
17
18
# File 'lib/sportdb/structs/goal_parser_csv.rb', line 16

def initialize( txt )
  @txt = txt
end

Class Method Details

.parse(txt) ⇒ Object



11
12
13
# File 'lib/sportdb/structs/goal_parser_csv.rb', line 11

def self.parse( txt )
   new( txt ).parse
end

.read(path) ⇒ Object



6
7
8
9
# File 'lib/sportdb/structs/goal_parser_csv.rb', line 6

def self.read( path )
   txt = File.open( path, 'r:utf-8' ) {|f| f.read }   ## note: make sure to use (assume) utf-8
   parse( txt )
end

Instance Method Details

#parseObject



20
21
22
23
24
25
# File 'lib/sportdb/structs/goal_parser_csv.rb', line 20

def parse
  rows = parse_csv( @txt )
  recs = rows.map { |row| Sports::GoalEvent.build( row ) }
  ## pp recs[0]
  recs
end