Module: SportDb::FixtureHelpers
- Included in:
- ClubSquadReader, GameReader, NationalTeamSquadReader
- Defined in:
- lib/sportdb/utils.rb,
lib/sportdb/utils_map.rb,
lib/sportdb/utils_date.rb,
lib/sportdb/utils_goals.rb,
lib/sportdb/utils_group.rb,
lib/sportdb/utils_round.rb,
lib/sportdb/utils_teams.rb,
lib/sportdb/utils_scores.rb
Instance Method Summary collapse
- #cut_off_end_of_line_comment!(line) ⇒ Object
- #find_date!(line, opts = {}) ⇒ Object
- #find_game_pos!(line) ⇒ Object
- #find_ground!(line) ⇒ Object
- #find_group_title_and_pos!(line) ⇒ Object
- #find_leading_num!(line) ⇒ Object
- #find_leading_pos!(line) ⇒ Object
- #find_nationality!(line) ⇒ Object
- #find_person!(line) ⇒ Object
- #find_round_def_title!(line) ⇒ Object
- #find_round_header_title!(line) ⇒ Object
-
#find_round_header_title2!(line) ⇒ Object
fix/todo: check that [ROUND.TITLE2] and friends do NOT use pipes (|) change all pipes (|) to dot (.) - pipes get used for def markers!!!.
- #find_round_pos!(line) ⇒ Object
- #find_scores!(line, opts = {}) ⇒ Object
-
#find_team!(line) ⇒ Object
NB: returns key (string or nil).
-
#find_team1!(line) ⇒ Object
todo: check if find_team1 gets used? if not remove it!! use find_teams!.
- #find_team2!(line) ⇒ Object
-
#find_teams!(line) ⇒ Object
NB: returns an array - note: plural! (teamsss).
- #is_goals?(line) ⇒ Boolean
- #is_group?(line) ⇒ Boolean
- #is_group_def?(line) ⇒ Boolean
- #is_knockout_round?(line) ⇒ Boolean
- #is_postponed?(line) ⇒ Boolean
- #is_round?(line) ⇒ Boolean
- #is_round_def?(line) ⇒ Boolean
-
#map_ground!(line, known_grounds = nil) ⇒ Object
todo/fix: pass in known_grounds as a parameter? why? why not? todo/fix: remove =nil in para - make param required w/o fallback.
-
#map_person!(line, known_persons = nil) ⇒ Object
todo/fix: remove =nil in para - make param required w/o fallback.
-
#map_team!(line) ⇒ Object
alias map_teams!.
-
#map_teams!(line) ⇒ Object
todo/fix: pass in known_teams as a parameter? why? why not?.
-
#match_teams!(line) ⇒ Object
depreciated methods - use map_.
Instance Method Details
#cut_off_end_of_line_comment!(line) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/sportdb/utils.rb', line 17 def cut_off_end_of_line_comment!( line ) # cut off (that is, remove) optional end of line comment starting w/ # line.sub!( /#.*$/ ) do |_| logger.debug " cutting off end of line comment - >>#{$&}<<" '' end # NB: line = line.sub will NOT work - thus, lets use line.sub! end |
#find_date!(line, opts = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/sportdb/utils_date.rb', line 12 def find_date!( line, opts={} ) ## NB: lets us pass in start_at/end_at date (for event) # for auto-complete year # extract date from line # and return it # NB: side effect - removes date from line string finder = DateFinder.new finder.find!( line, opts ) end |
#find_game_pos!(line) ⇒ Object
81 82 83 84 |
# File 'lib/sportdb/utils.rb', line 81 def find_game_pos!( line ) ## fix: add depreciation warning - remove - use find_leading_pos! find_leading_pos!( line ) end |
#find_ground!(line) ⇒ Object
7 8 9 |
# File 'lib/sportdb/utils_map.rb', line 7 def find_ground!( line ) TextUtils.find_key_for!( 'ground', line ) end |
#find_group_title_and_pos!(line) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/sportdb/utils_group.rb', line 18 def find_group_title_and_pos!( line ) ## group pos - for now support single digit e.g 1,2,3 or letter e.g. A,B,C or HEX ## nb: (?:) = is for non-capturing group(ing) ## fix: ## get Group|Gruppe|Grupo from lang!!!! do NOT hardcode in place ## todo: ## check if Group A: or [Group A] works e.g. : or ] get matched by \b ??? regex = /(?:Group|Gruppe|Grupo)\s+((?:\d{1}|[A-Z]{1,3}))\b/ match = regex.match( line ) return [nil,nil] if match.nil? pos = case match[1] when 'A' then 1 when 'B' then 2 when 'C' then 3 when 'D' then 4 when 'E' then 5 when 'F' then 6 when 'G' then 7 when 'H' then 8 when 'I' then 9 when 'J' then 10 when 'K' then 11 when 'L' then 12 when 'HEX' then 666 # HEX for Hexagonal - todo/check: map to something else ?? else match[1].to_i end title = match[0] logger.debug " title: >#{title}<" logger.debug " pos: >#{pos}<" line.sub!( regex, '[GROUP.TITLE+POS]' ) return [title,pos] end |
#find_leading_num!(line) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/sportdb/utils.rb', line 46 def find_leading_num!( line ) # extract optional leading num from line e.g. 9 Lionel Messi # and return it # NB: side effect - removes num from line string # e.g. 9 Lionel Messi - must start line ## note: use lookahead (?=) for trailing spaces - do NOT cosume regex = /^[ \t]*(\d{1,3})(?=[ \t]+)/ if line =~ regex logger.debug " num: >#{$1}<" line.sub!( regex, '[NUM]' ) return $1.to_i else return nil end end |
#find_leading_pos!(line) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/sportdb/utils.rb', line 64 def find_leading_pos!( line ) # extract optional game pos from line # and return it # NB: side effect - removes pos from line string # e.g. (1) - must start line regex = /^[ \t]*\((\d{1,3})\)[ \t]+/ if line =~ regex logger.debug " pos: >#{$1}<" line.sub!( regex, '[POS] ' ) # NB: add trailing space return $1.to_i else return nil end end |
#find_nationality!(line) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/sportdb/utils.rb', line 29 def find_nationality!( line ) # extract optional nationality - three-letter country code from line e.g. Lionel Messi (ARG) # and return it # NB: side effect - removes num from line string regex = /\(([A-Z]{3})\)/ # e.g. (ARG) if line =~ regex logger.debug " nationality: >#{$1}<" line.sub!( regex, '[NATIONALITY]' ) return $1.to_s else return nil end end |
#find_person!(line) ⇒ Object
26 27 28 |
# File 'lib/sportdb/utils_map.rb', line 26 def find_person!( line ) TextUtils.find_key_for!( 'person', line ) end |
#find_round_def_title!(line) ⇒ Object
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 |
# File 'lib/sportdb/utils_round.rb', line 90 def find_round_def_title!( line ) # assume everything before pipe (\) is the round title # strip [ROUND.POS], todo:?? [ROUND.TITLE2] # todo/fix: add title2 w/ // or / why? why not? # -- strip / or / chars buf = line.dup logger.debug " find_round_def_title! line-before: >>#{buf}<<" ## cut-off everything after (including) pipe (|) buf = buf[ 0...buf.index('|') ] # e.g. remove [ROUND.POS], [ROUND.TITLE2], [GROUP.TITLE+POS] etc. buf.gsub!( /\[[^\]]+\]/, '' ) ## fix: use helper for (re)use e.g. remove_match_placeholder/marker or similar? # remove leading and trailing whitespace buf.strip! logger.debug " find_round_def_title! line-after: >>#{buf}<<" logger.debug " title: >>#{buf}<<" line.sub!( buf, '[ROUND.TITLE]' ) buf end |
#find_round_header_title!(line) ⇒ Object
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 |
# File 'lib/sportdb/utils_round.rb', line 62 def find_round_header_title!( line ) # assume everything left is the round title # extract all other items first (round title2, round pos, group title n pos, etc.) ## todo/fix: ## cleanup method ## use buf.index( '//' ) to split string (see found_round_def) ## why? simpler why not? ## - do we currently allow groups if title2 present? add example if it works? buf = line.dup logger.debug " find_round_header_title! line-before: >>#{buf}<<" buf.gsub!( /\[[^\]]+\]/, '' ) # e.g. remove [ROUND.POS], [ROUND.TITLE2], [GROUP.TITLE+POS] etc. buf.sub!( /\s+[\/\-]{1,}\s+$/, '' ) # remove optional trailing / or / chars (left over from group) buf.strip! # remove leading and trailing whitespace logger.debug " find_round_title! line-after: >>#{buf}<<" ### bingo - assume what's left is the round title logger.debug " title: >>#{buf}<<" line.sub!( buf, '[ROUND.TITLE]' ) buf end |
#find_round_header_title2!(line) ⇒ Object
fix/todo: check that [ROUND.TITLE2] and friends do NOT use pipes (|)
change all pipes (|) to dot (.)
-
pipes get used for def markers!!!
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/sportdb/utils_round.rb', line 41 def find_round_header_title2!( line ) ## todo/fix: ## cleanup method ## use buf.index( '//' ) to split string (see found_round_def) ## why? simpler why not? ## - do we currently allow groups if title2 present? add example if it works? # assume everything after // is title2 - strip off leading n trailing whitespaces regex = /\/{2,}\s*(.+)\s*$/ if line =~ regex logger.debug " title2: >#{$1}<" line.sub!( regex, '[ROUND.TITLE2]' ) return $1 else return nil # no round title2 found (title2 is optional) end end |
#find_round_pos!(line) ⇒ Object
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 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/sportdb/utils_round.rb', line 117 def find_round_pos!( line ) # pass #1) extract optional round pos from line # e.g. (1) - must start line regex_pos = /^[ \t]*\((\d{1,3})\)[ \t]+/ # pass #2) find free standing number e.g. Matchday 3 or Round 5 or 3. Spieltag etc. # note: /\b(\d{1,3})\b/ # will match -12 # thus, use space required - will NOT match -2 e.g. Group-2 Play-off # note: allow 1. Runde n # 1^ Giornata regex_num = /(?:^|\s)(\d{1,3})(?:[.\^\s]|$)/ if line =~ regex_pos logger.debug " pos: >#{$1}<" line.sub!( regex_pos, '[ROUND.POS] ' ) ## NB: add back trailing space that got swallowed w/ regex -> [ \t]+ return $1.to_i elsif line =~ regex_num ## assume number in title is pos (e.g. Jornada 3, 3 Runde etc.) ## NB: do NOT remove pos from string (will get removed by round title) num = $1.to_i # note: clone capture; keep a copy (another regex follows; will redefine $1) #### fix: # use/make keywords required # e.g. Round of 16 -> should NOT match 16! # Spiel um Platz 3 (or 5) etc -> should NOT match 3! # Round 16 - ok # thus, check for required keywords ## quick hack for round of 16 # todo: mask match e.g. Round of xxx ... and try again - might include something # reuse pattern for Group XX Replays for example if line =~ /^\s*Round of \d{1,3}\b/ return nil end logger.debug " pos: >#{num}<" return num else ## fix: add logger.warn no round pos found in line return nil end end |
#find_scores!(line, opts = {}) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/sportdb/utils_scores.rb', line 7 def find_scores!( line, opts={} ) # note: always call after find_dates !!! # scores match date-like patterns!! e.g. 10-11 or 10:00 etc. # -- note: score might have two digits too finder = ScoresFinder.new finder.find!( line, opts ) end |
#find_team!(line) ⇒ Object
NB: returns key (string or nil)
12 13 14 15 |
# File 'lib/sportdb/utils_teams.rb', line 12 def find_team!( line ) # NB: returns key (string or nil) puts "*** find_team! deprecated -- use TeamMapper!!!" TextUtils.find_key_for!( 'team', line ) end |
#find_team1!(line) ⇒ Object
todo: check if find_team1 gets used? if not remove it!! use find_teams!
18 19 20 21 |
# File 'lib/sportdb/utils_teams.rb', line 18 def find_team1!( line ) puts "*** find_team1! deprecated -- use TeamMapper!!!" TextUtils.find_key_for!( 'team1', line ) end |
#find_team2!(line) ⇒ Object
23 24 25 26 |
# File 'lib/sportdb/utils_teams.rb', line 23 def find_team2!( line ) puts "*** find_team2! deprecated -- use TeamMapper!!!" TextUtils.find_key_for!( 'team2', line ) end |
#find_teams!(line) ⇒ Object
NB: returns an array - note: plural! (teamsss)
7 8 9 10 |
# File 'lib/sportdb/utils_teams.rb', line 7 def find_teams!( line ) # NB: returns an array - note: plural! (teamsss) puts "*** find_teams! deprecated -- use TeamMapper!!!" TextUtils.find_keys_for!( 'team', line ) end |
#is_goals?(line) ⇒ Boolean
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/sportdb/utils_goals.rb', line 6 def is_goals?( line ) # check if is goals line # e.g. looks like # Neymar 29', 71' (pen.) Oscar 90+1'; Marcelo 11' (o.g.) # check for # <space>90' or # <space>90+1' line =~ /[ ](\d{1,3}\+)?\d{1,3}'/ end |
#is_group?(line) ⇒ Boolean
12 13 14 15 16 |
# File 'lib/sportdb/utils_group.rb', line 12 def is_group?( line ) # NB: check after is_round? (round may contain group reference!) ## note: =~ return nil if not match found, and 0,1, etc for match (line =~ SportDb.lang.regex_group) != nil end |
#is_group_def?(line) ⇒ Boolean
6 7 8 9 10 |
# File 'lib/sportdb/utils_group.rb', line 6 def is_group_def?( line ) # NB: check after is_round? (round may contain group reference!) ## must include bar (|) marker (make required) line =~ /\|/ && is_group?( line ) end |
#is_knockout_round?(line) ⇒ Boolean
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/sportdb/utils_round.rb', line 16 def is_knockout_round?( line ) ## todo: check for adding ignore case for regex (e.g. 1st leg/1st Leg) if line =~ SportDb.lang.regex_leg1 logger.debug " two leg knockout; skip knockout flag on first leg" false elsif line =~ SportDb.lang.regex_knockout_round logger.debug " setting knockout flag to true" true elsif line =~ /K\.O\.|K\.o\.|Knockout/ ## NB: add two language independent markers, that is, K.O. and Knockout logger.debug " setting knockout flag to true (lang independent marker)" true else false end end |
#is_postponed?(line) ⇒ Boolean
6 7 8 9 |
# File 'lib/sportdb/utils_date.rb', line 6 def is_postponed?( line ) # check if line include postponed marker e.g. => line =~ /=>/ end |
#is_round?(line) ⇒ Boolean
11 12 13 14 |
# File 'lib/sportdb/utils_round.rb', line 11 def is_round?( line ) ## note: =~ return nil if not match found, and 0,1, etc for match (line =~ SportDb.lang.regex_round) != nil end |
#is_round_def?(line) ⇒ Boolean
6 7 8 9 |
# File 'lib/sportdb/utils_round.rb', line 6 def is_round_def?( line ) ## must include bar (|) marker (make required) line =~ /\|/ && is_round?( line ) end |
#map_ground!(line, known_grounds = nil) ⇒ Object
todo/fix: pass in known_grounds as a parameter? why? why not? todo/fix:
remove =nil in para - make param required w/o fallback
15 16 17 18 19 20 21 22 |
# File 'lib/sportdb/utils_map.rb', line 15 def map_ground!( line, known_grounds=nil ) if known_grounds.nil? puts "depreciated API call map_ground! (pass in mapping table as 2nd param)" known_grounds = @known_grounds end TextUtils.map_titles_for!( 'ground', line, known_grounds ) end |
#map_person!(line, known_persons = nil) ⇒ Object
todo/fix:
remove =nil in para - make param required w/o fallback
32 33 34 35 36 37 38 39 |
# File 'lib/sportdb/utils_map.rb', line 32 def map_person!( line, known_persons=nil ) if known_persons.nil? puts "depreciated API call map_person! (pass in mapping table as 2nd param)" known_persons = @known_persons end TextUtils.map_titles_for!( 'person', line, known_persons ) end |
#map_team!(line) ⇒ Object
alias map_teams!
35 36 37 |
# File 'lib/sportdb/utils_teams.rb', line 35 def map_team!( line ) # alias map_teams! map_teams!( line ) end |
#map_teams!(line) ⇒ Object
todo/fix: pass in known_teams as a parameter? why? why not?
30 31 32 33 |
# File 'lib/sportdb/utils_teams.rb', line 30 def map_teams!( line ) puts "*** map_teams! deprecated -- use TeamMapper!!!" TextUtils.map_titles_for!( 'team', line, @known_teams ) end |
#match_teams!(line) ⇒ Object
depreciated methods - use map_
41 42 43 44 |
# File 'lib/sportdb/utils_teams.rb', line 41 def match_teams!( line ) ## fix: rename to map_teams!! - remove match_teams! ## todo: issue depreciated warning map_teams!( line ) end |