Class: SportDb::GoalsParser

Inherits:
Object
  • Object
show all
Includes:
LogUtils::Logging
Defined in:
lib/sportdb/finders/goals.rb

Constant Summary collapse

NAME_REGEX =

note: use ^ for start of string only!!!

  • for now slurp everything up to digits (inlc. spaces - use strip to remove)

todo/check: use/rename to NAME_UNTIL_REGEX ??? ( add lookahead for spaces?)

/^
 [^0-9]+
/x
MINUTES_REGEX =

todo/check: change to MINUTE_REGEX ?? add MINUTE_SKIP_REGEX or MINUTE_SEP_REGEX /^[ ,]+/ todo/fix: split out penalty and owngoal flag in PATTERN constant for reuse

/^      # note: use ^ for start of string only!!!
  (?<minute>[0-9]{1,3})
  (?:\+
    (?<offset>[1-9]{1})
  )?
  '
  (?:[ ]*
    \(
    (?<type>P|pen\.|o\.g\.)
    \)
  )?
/x

Instance Method Summary collapse

Constructor Details

#initializeGoalsParser

Returns a new instance of GoalsParser.



185
186
187
# File 'lib/sportdb/finders/goals.rb', line 185

def initialize
  # nothing here for now

end

Instance Method Details

#parse!(line, opts = {}) ⇒ Object



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/sportdb/finders/goals.rb', line 189

def parse!( line, opts={} )

  ## for now assume

  ##    everything up-to  0-9 and , and () is part of player name 


  ## try parsing lhs

  ##  todo: check for  empty -    remove (make it same as empty string)


  players = []

  name = get_player_name!( line )
  while name
    logger.debug "  found player name >#{name}< - remaining >#{line}<"
    
    player = GoalsPlayerStruct.new
    player.name = name
    
    minute_hash = get_minute_hash!( line )
    while minute_hash
      logger.debug "  found minutes >#{minute_hash.inspect}< - remaining >#{line}<"

      minute = GoalsMinuteStruct.new
      minute.minute = minute_hash[:minute].to_i
      minute.offset = minute_hash[:offset].to_i  if minute_hash[:offset]
      if minute_hash[:type]
        minute.owngoal = true  if minute_hash[:type] =~ /o\.g\./
        minute.penalty = true  if minute_hash[:type] =~ /P|pen\./
      end
      player.minutes << minute

      # remove commas and spaces (note: use ^ for start of string only!!!)

      line.sub!( /^[ ,]+/, '' )
      minute_hash = get_minute_hash!( line )
    end
    
    players << player
    name = get_player_name!( line )
  end

  players
end