Class: SportDb::GoalsParser

Inherits:
Object
  • Object
show all
Includes:
LogUtils::Logging
Defined in:
lib/sportdb/formats/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.



202
203
204
# File 'lib/sportdb/formats/goals.rb', line 202

def initialize
  # nothing here for now
end

Instance Method Details

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



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/sportdb/formats/goals.rb', line 206

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