Class: SportDb::GoalsFinder
- Inherits:
-
Object
- Object
- SportDb::GoalsFinder
- Includes:
- LogUtils::Logging, FixtureHelpers
- Defined in:
- lib/sportdb/finders/goals.rb
Overview
todo: find a better name? to avoid confusing w/ GoalsParser? use MatchGoalsParser or similar?
Instance Method Summary collapse
- #find!(line, opts = {}) ⇒ Object
-
#initialize ⇒ GoalsFinder
constructor
A new instance of GoalsFinder.
Methods included from FixtureHelpers
#cut_off_end_of_line_comment!, #find_date!, #find_game_pos!, #find_ground!, #find_group_title_and_pos!, #find_leading_num!, #find_leading_pos!, #find_nationality!, #find_person!, #find_round_def_title!, #find_round_header_title!, #find_round_header_title2!, #find_round_pos!, #find_rsssf_date!, #find_scores!, #find_team!, #find_team1!, #find_team2!, #find_teams!, #is_goals?, #is_group?, #is_group_def?, #is_knockout_round?, #is_postponed?, #is_round?, #is_round_def?, #map_ground!, #map_person!, #map_team!, #map_teams!, #match_teams!
Constructor Details
#initialize ⇒ GoalsFinder
Returns a new instance of GoalsFinder.
56 57 58 |
# File 'lib/sportdb/finders/goals.rb', line 56 def initialize # nothing here for now end |
Instance Method Details
#find!(line, opts = {}) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/sportdb/finders/goals.rb', line 60 def find!( line, opts={} ) # remove end-of-line comments # - move to textutils ?? why? why not?? cut_off_end_of_line_comment!( line ) ## note: func defined in utils.rb (FixtureHelpers) # remove [] if presents e.g. [Neymar 12'] line = line.gsub( /[\[\]]/, '' ) # remove (single match) if line starts w/ - (allow spaces) e.g. [-;Neymar 12'] or [ - ;Neymar 12'] line = line.sub( /^[ ]*-[ ]*/, '' ) # split into left hand side (lhs) for team1 and # right hand side (rhs) for team2 values = line.split( ';' ) # note: allow empty right hand side (e.g. team2 did NOT score any goals e.g. 3-0 etc.) lhs = values[0] rhs = values[1] lhs = lhs.strip unless lhs.nil? rhs = rhs.strip unless rhs.nil? parser = GoalsParser.new ## todo/check: only call if not nil? logger.debug " lhs (team1): >#{lhs}<" lhs_data = parser.parse!( lhs ) pp lhs_data logger.debug " rhs (team2): >#{rhs}<" rhs_data = parser.parse!( rhs ) pp rhs_data ### merge into flat goal structs goals = [] lhs_data.each do |player| player.minutes.each do |minute| goal = GoalStruct.new goal.name = player.name goal.team = 1 goal.minute = minute.minute goal.offset = minute.offset goal.penalty = minute.penalty goal.owngoal = minute.owngoal goals << goal end end rhs_data.each do |player| player.minutes.each do |minute| goal = GoalStruct.new goal.name = player.name goal.team = 2 goal.minute = minute.minute goal.offset = minute.offset goal.penalty = minute.penalty goal.owngoal = minute.owngoal goals << goal end end # sort by minute + offset goals = goals.sort do |l,r| res = l.minute <=> r.minute if res == 0 res = l.offset <=> r.offset # pass 2: sort by offset end res end ## calc score1,score2 score1 = 0 score2 = 0 goals.each do |goal| if goal.team == 1 score1 += 1 elsif goal.team == 2 score2 += 1 else # todo: should not happen: issue warning end goal.score1 = score1 goal.score2 = score2 end logger.debug " #{goals.size} goals:" pp goals goals end |