sportdb-models 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gemtest +0 -0
- data/HISTORY.md +21 -0
- data/Manifest.txt +142 -0
- data/README.md +28 -0
- data/Rakefile +59 -0
- data/config/fixtures/de.yml +46 -0
- data/config/fixtures/en.yml +54 -0
- data/config/fixtures/es.yml +48 -0
- data/config/fixtures/fr.yml +53 -0
- data/config/fixtures/it.yml +55 -0
- data/config/fixtures/pt.yml +46 -0
- data/config/fixtures/ro.yml +55 -0
- data/data/seasons.txt +74 -0
- data/data/setups/all.txt +5 -0
- data/lib/sportdb/calc.rb +279 -0
- data/lib/sportdb/deleter.rb +52 -0
- data/lib/sportdb/finders/date.rb +374 -0
- data/lib/sportdb/finders/goals.rb +260 -0
- data/lib/sportdb/finders/scores.rb +122 -0
- data/lib/sportdb/lang.rb +216 -0
- data/lib/sportdb/matcher.rb +31 -0
- data/lib/sportdb/models.rb +259 -0
- data/lib/sportdb/models/assoc.rb +106 -0
- data/lib/sportdb/models/assoc_assoc.rb +15 -0
- data/lib/sportdb/models/badge.rb +14 -0
- data/lib/sportdb/models/event.rb +65 -0
- data/lib/sportdb/models/event_ground.rb +15 -0
- data/lib/sportdb/models/event_team.rb +16 -0
- data/lib/sportdb/models/forward.rb +55 -0
- data/lib/sportdb/models/game.rb +244 -0
- data/lib/sportdb/models/goal.rb +15 -0
- data/lib/sportdb/models/ground.rb +100 -0
- data/lib/sportdb/models/group.rb +23 -0
- data/lib/sportdb/models/group_team.rb +14 -0
- data/lib/sportdb/models/league.rb +83 -0
- data/lib/sportdb/models/person.rb +21 -0
- data/lib/sportdb/models/roster.rb +18 -0
- data/lib/sportdb/models/round.rb +22 -0
- data/lib/sportdb/models/season.rb +14 -0
- data/lib/sportdb/models/stats/alltime_standing.rb +44 -0
- data/lib/sportdb/models/stats/alltime_standing_entry.rb +23 -0
- data/lib/sportdb/models/stats/event_standing.rb +55 -0
- data/lib/sportdb/models/stats/event_standing_entry.rb +21 -0
- data/lib/sportdb/models/stats/group_standing.rb +50 -0
- data/lib/sportdb/models/stats/group_standing_entry.rb +22 -0
- data/lib/sportdb/models/team.rb +119 -0
- data/lib/sportdb/models/team_comp.rb +64 -0
- data/lib/sportdb/models/utils.rb +78 -0
- data/lib/sportdb/models/world/city.rb +21 -0
- data/lib/sportdb/models/world/continent.rb +20 -0
- data/lib/sportdb/models/world/country.rb +19 -0
- data/lib/sportdb/models/world/region.rb +19 -0
- data/lib/sportdb/patterns.rb +38 -0
- data/lib/sportdb/reader.rb +130 -0
- data/lib/sportdb/reader_file.rb +123 -0
- data/lib/sportdb/reader_zip.rb +165 -0
- data/lib/sportdb/readers/assoc.rb +54 -0
- data/lib/sportdb/readers/event.rb +200 -0
- data/lib/sportdb/readers/game.rb +877 -0
- data/lib/sportdb/readers/ground.rb +53 -0
- data/lib/sportdb/readers/league.rb +54 -0
- data/lib/sportdb/readers/season.rb +83 -0
- data/lib/sportdb/readers/squad_club.rb +201 -0
- data/lib/sportdb/readers/squad_national_team.rb +173 -0
- data/lib/sportdb/readers/team.rb +53 -0
- data/lib/sportdb/schema.rb +373 -0
- data/lib/sportdb/standings.rb +178 -0
- data/lib/sportdb/stats.rb +27 -0
- data/lib/sportdb/utils.rb +89 -0
- data/lib/sportdb/utils_date.rb +26 -0
- data/lib/sportdb/utils_goals.rb +20 -0
- data/lib/sportdb/utils_group.rb +63 -0
- data/lib/sportdb/utils_map.rb +44 -0
- data/lib/sportdb/utils_round.rb +165 -0
- data/lib/sportdb/utils_scores.rb +17 -0
- data/lib/sportdb/utils_teams.rb +43 -0
- data/lib/sportdb/version.rb +23 -0
- data/test/data/at-austria/2013_14/bl.txt +227 -0
- data/test/data/at-austria/2013_14/bl.yml +30 -0
- data/test/data/at-austria/2013_14/bl_ii.txt +154 -0
- data/test/data/at-austria/2013_14/el.txt +4 -0
- data/test/data/at-austria/2013_14/el.yml +25 -0
- data/test/data/at-austria/2013_14/squads/austria.txt +40 -0
- data/test/data/at-austria/2013_14/squads/salzburg.txt +35 -0
- data/test/data/at-austria/leagues.txt +11 -0
- data/test/data/at-austria/teams.txt +75 -0
- data/test/data/at-austria/teams_2.txt +34 -0
- data/test/data/national-teams/assocs.txt +231 -0
- data/test/data/national-teams/europe/assocs.txt +13 -0
- data/test/data/national-teams/europe/teams.txt +13 -0
- data/test/data/national-teams/north-america/assocs.txt +10 -0
- data/test/data/national-teams/north-america/teams.txt +7 -0
- data/test/data/national-teams/teams.txt +19 -0
- data/test/data/players/europe/at-austria/players.txt +45 -0
- data/test/data/players/europe/de-deutschland/players.txt +41 -0
- data/test/data/players/south-america/br-brazil/players.txt +51 -0
- data/test/data/world-cup/1930/cup.txt +71 -0
- data/test/data/world-cup/1930/cup.yml +23 -0
- data/test/data/world-cup/1930/cup_goals.txt +47 -0
- data/test/data/world-cup/1930/cup_goals.yml +23 -0
- data/test/data/world-cup/1954/cup.txt +90 -0
- data/test/data/world-cup/1954/cup.yml +30 -0
- data/test/data/world-cup/1962/cup.txt +86 -0
- data/test/data/world-cup/1962/cup.yml +32 -0
- data/test/data/world-cup/1974/cup.yml +35 -0
- data/test/data/world-cup/1974/cup_finals.txt +14 -0
- data/test/data/world-cup/1974/cup_i.txt +55 -0
- data/test/data/world-cup/1974/cup_ii.txt +34 -0
- data/test/data/world-cup/2014/cup.txt +5 -0
- data/test/data/world-cup/2014/cup.yml +54 -0
- data/test/data/world-cup/2014/squads/br-brazil.txt +46 -0
- data/test/data/world-cup/2014/squads/de-deutschland.txt +8 -0
- data/test/data/world-cup/2014/squads/jp-japan.txt +30 -0
- data/test/data/world-cup/2014/squads/uy-uruguay.txt +32 -0
- data/test/data/world-cup/leagues.txt +5 -0
- data/test/data/world-cup/seasons_1930.txt +4 -0
- data/test/data/world-cup/seasons_1954.txt +4 -0
- data/test/data/world-cup/seasons_1962.txt +4 -0
- data/test/data/world-cup/seasons_1974.txt +5 -0
- data/test/data/world-cup/teams_1930.txt +26 -0
- data/test/data/world-cup/teams_1954.txt +30 -0
- data/test/data/world-cup/teams_1962.txt +29 -0
- data/test/data/world-cup/teams_1974.txt +29 -0
- data/test/helper.rb +120 -0
- data/test/test_assoc_reader.rb +201 -0
- data/test/test_changes.rb +74 -0
- data/test/test_cursor.rb +50 -0
- data/test/test_date.rb +100 -0
- data/test/test_goals.rb +109 -0
- data/test/test_lang.rb +130 -0
- data/test/test_load.rb +61 -0
- data/test/test_reader.rb +88 -0
- data/test/test_reader_from_string.rb +65 -0
- data/test/test_round_auto.rb +370 -0
- data/test/test_round_def.rb +109 -0
- data/test/test_round_header.rb +183 -0
- data/test/test_scores.rb +70 -0
- data/test/test_squad_club_reader.rb +76 -0
- data/test/test_squad_national_team_reader.rb +116 -0
- data/test/test_standings.rb +279 -0
- data/test/test_standings_ii.rb +46 -0
- data/test/test_utils.rb +124 -0
- data/test/test_winner.rb +95 -0
- metadata +378 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
module SportDb
|
3
|
+
|
4
|
+
class Stats
|
5
|
+
include Models
|
6
|
+
|
7
|
+
def tables
|
8
|
+
puts " #{League.count} leagues / #{Season.count} seasons"
|
9
|
+
puts " #{Event.count} events (league+season recs) / #{Round.count} rounds / #{Group.count} groups"
|
10
|
+
puts " #{Team.count} teams"
|
11
|
+
puts " #{Game.count} games"
|
12
|
+
puts " #{Badge.count} badges"
|
13
|
+
|
14
|
+
puts " #{Roster.count} rosters (person+team+event recs)"
|
15
|
+
puts " #{Goal.count} goals (person+game recs)"
|
16
|
+
|
17
|
+
puts " #{Assoc.count} assocs|orgs"
|
18
|
+
puts " #{Ground.count} grounds|stadiums"
|
19
|
+
|
20
|
+
## note: moved to racing.db -- remove/delete!!
|
21
|
+
## puts " #{Track.count} tracks / #{Race.count} races (track+event recs) / #{Run.count} runs"
|
22
|
+
## puts " #{Record.count} records (race|run+person recs)"
|
23
|
+
end
|
24
|
+
|
25
|
+
end # class Stats
|
26
|
+
|
27
|
+
end # module SportDb
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
### note: some utils moved to worldbdb/utils for reuse
|
4
|
+
|
5
|
+
|
6
|
+
####
|
7
|
+
## move to folder matcher(s)/finder(s)
|
8
|
+
# -- rename to FixtureFinder or FixtureFinders
|
9
|
+
# or just GeneralFinder
|
10
|
+
# TeamFinder etc. ???
|
11
|
+
|
12
|
+
|
13
|
+
module SportDb
|
14
|
+
module FixtureHelpers
|
15
|
+
|
16
|
+
|
17
|
+
def cut_off_end_of_line_comment!( line )
|
18
|
+
# cut off (that is, remove) optional end of line comment starting w/ #
|
19
|
+
|
20
|
+
line.sub!( /#.*$/ ) do |_|
|
21
|
+
logger.debug " cutting off end of line comment - >>#{$&}<<"
|
22
|
+
''
|
23
|
+
end
|
24
|
+
|
25
|
+
# NB: line = line.sub will NOT work - thus, lets use line.sub!
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
def find_nationality!( line )
|
30
|
+
# extract optional nationality - three-letter country code from line e.g. Lionel Messi (ARG)
|
31
|
+
# and return it
|
32
|
+
# NB: side effect - removes num from line string
|
33
|
+
|
34
|
+
regex = /\(([A-Z]{3})\)/ # e.g. (ARG)
|
35
|
+
if line =~ regex
|
36
|
+
logger.debug " nationality: >#{$1}<"
|
37
|
+
|
38
|
+
line.sub!( regex, '[NATIONALITY]' )
|
39
|
+
return $1.to_s
|
40
|
+
else
|
41
|
+
return nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
def find_leading_num!( line )
|
47
|
+
# extract optional leading num from line e.g. 9 Lionel Messi
|
48
|
+
# and return it
|
49
|
+
# NB: side effect - removes num from line string
|
50
|
+
|
51
|
+
# e.g. 9 Lionel Messi - must start line
|
52
|
+
## note: use lookahead (?=) for trailing spaces - do NOT cosume
|
53
|
+
regex = /^[ \t]*(\d{1,3})(?=[ \t]+)/
|
54
|
+
if line =~ regex
|
55
|
+
logger.debug " num: >#{$1}<"
|
56
|
+
|
57
|
+
line.sub!( regex, '[NUM]' )
|
58
|
+
return $1.to_i
|
59
|
+
else
|
60
|
+
return nil
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def find_leading_pos!( line )
|
65
|
+
# extract optional game pos from line
|
66
|
+
# and return it
|
67
|
+
# NB: side effect - removes pos from line string
|
68
|
+
|
69
|
+
# e.g. (1) - must start line
|
70
|
+
regex = /^[ \t]*\((\d{1,3})\)[ \t]+/
|
71
|
+
if line =~ regex
|
72
|
+
logger.debug " pos: >#{$1}<"
|
73
|
+
|
74
|
+
line.sub!( regex, '[POS] ' ) # NB: add trailing space
|
75
|
+
return $1.to_i
|
76
|
+
else
|
77
|
+
return nil
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def find_game_pos!( line )
|
82
|
+
## fix: add depreciation warning - remove - use find_leading_pos!
|
83
|
+
find_leading_pos!( line )
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
end # module FixtureHelpers
|
89
|
+
end # module SportDb
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module SportDb
|
4
|
+
module FixtureHelpers
|
5
|
+
|
6
|
+
def is_postponed?( line )
|
7
|
+
# check if line include postponed marker e.g. =>
|
8
|
+
line =~ /=>/
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
def find_date!( line, opts={} )
|
13
|
+
## NB: lets us pass in start_at/end_at date (for event)
|
14
|
+
# for auto-complete year
|
15
|
+
|
16
|
+
# extract date from line
|
17
|
+
# and return it
|
18
|
+
# NB: side effect - removes date from line string
|
19
|
+
|
20
|
+
finder = DateFinder.new
|
21
|
+
finder.find!( line, opts )
|
22
|
+
end
|
23
|
+
|
24
|
+
end # module FixtureHelpers
|
25
|
+
end # module SportDb
|
26
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module SportDb
|
4
|
+
module FixtureHelpers
|
5
|
+
|
6
|
+
def is_goals?( line )
|
7
|
+
# check if is goals line
|
8
|
+
# e.g. looks like
|
9
|
+
# Neymar 29', 71' (pen.) Oscar 90+1'; Marcelo 11' (o.g.)
|
10
|
+
# check for
|
11
|
+
# <space>90' or
|
12
|
+
# <space>90+1'
|
13
|
+
|
14
|
+
line =~ /[ ](\d{1,3}\+)?\d{1,3}'/
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
end # module FixtureHelpers
|
19
|
+
end # module SportDb
|
20
|
+
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module SportDb
|
4
|
+
module FixtureHelpers
|
5
|
+
|
6
|
+
def is_group_def?( line )
|
7
|
+
# NB: check after is_round? (round may contain group reference!)
|
8
|
+
## must include bar (|) marker (make required)
|
9
|
+
line =~ /\|/ && is_group?( line )
|
10
|
+
end
|
11
|
+
|
12
|
+
def is_group?( line )
|
13
|
+
# NB: check after is_round? (round may contain group reference!)
|
14
|
+
## note: =~ return nil if not match found, and 0,1, etc for match
|
15
|
+
(line =~ SportDb.lang.regex_group) != nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def find_group_title_and_pos!( line )
|
19
|
+
## group pos - for now support single digit e.g 1,2,3 or letter e.g. A,B,C or HEX
|
20
|
+
## nb: (?:) = is for non-capturing group(ing)
|
21
|
+
|
22
|
+
## fix:
|
23
|
+
## get Group|Gruppe|Grupo from lang!!!! do NOT hardcode in place
|
24
|
+
|
25
|
+
## todo:
|
26
|
+
## check if Group A: or [Group A] works e.g. : or ] get matched by \b ???
|
27
|
+
regex = /(?:Group|Gruppe|Grupo)\s+((?:\d{1}|[A-Z]{1,3}))\b/
|
28
|
+
|
29
|
+
match = regex.match( line )
|
30
|
+
|
31
|
+
return [nil,nil] if match.nil?
|
32
|
+
|
33
|
+
pos = case match[1]
|
34
|
+
when 'A' then 1
|
35
|
+
when 'B' then 2
|
36
|
+
when 'C' then 3
|
37
|
+
when 'D' then 4
|
38
|
+
when 'E' then 5
|
39
|
+
when 'F' then 6
|
40
|
+
when 'G' then 7
|
41
|
+
when 'H' then 8
|
42
|
+
when 'I' then 9
|
43
|
+
when 'J' then 10
|
44
|
+
when 'K' then 11
|
45
|
+
when 'L' then 12
|
46
|
+
when 'HEX' then 666 # HEX for Hexagonal - todo/check: map to something else ??
|
47
|
+
else match[1].to_i
|
48
|
+
end
|
49
|
+
|
50
|
+
title = match[0]
|
51
|
+
|
52
|
+
logger.debug " title: >#{title}<"
|
53
|
+
logger.debug " pos: >#{pos}<"
|
54
|
+
|
55
|
+
line.sub!( regex, '[GROUP.TITLE+POS]' )
|
56
|
+
|
57
|
+
return [title,pos]
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
end # module FixtureHelpers
|
63
|
+
end # module SportDb
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module SportDb
|
4
|
+
module FixtureHelpers
|
5
|
+
|
6
|
+
|
7
|
+
def find_ground!( line )
|
8
|
+
TextUtils.find_key_for!( 'ground', line )
|
9
|
+
end
|
10
|
+
|
11
|
+
## todo/fix: pass in known_grounds as a parameter? why? why not?
|
12
|
+
### todo/fix:
|
13
|
+
## remove =nil in para - make param required w/o fallback
|
14
|
+
|
15
|
+
def map_ground!( line, known_grounds=nil )
|
16
|
+
if known_grounds.nil?
|
17
|
+
puts "depreciated API call map_ground! (pass in mapping table as 2nd param)"
|
18
|
+
known_grounds = @known_grounds
|
19
|
+
end
|
20
|
+
|
21
|
+
TextUtils.map_titles_for!( 'ground', line, known_grounds )
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
def find_person!( line )
|
27
|
+
TextUtils.find_key_for!( 'person', line )
|
28
|
+
end
|
29
|
+
|
30
|
+
### todo/fix:
|
31
|
+
## remove =nil in para - make param required w/o fallback
|
32
|
+
def map_person!( line, known_persons=nil )
|
33
|
+
if known_persons.nil?
|
34
|
+
puts "depreciated API call map_person! (pass in mapping table as 2nd param)"
|
35
|
+
known_persons = @known_persons
|
36
|
+
end
|
37
|
+
|
38
|
+
TextUtils.map_titles_for!( 'person', line, known_persons )
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
end # module FixtureHelpers
|
43
|
+
end # module SportDb
|
44
|
+
|
@@ -0,0 +1,165 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module SportDb
|
4
|
+
module FixtureHelpers
|
5
|
+
|
6
|
+
def is_round_def?( line )
|
7
|
+
## must include bar (|) marker (make required)
|
8
|
+
line =~ /\|/ && is_round?( line )
|
9
|
+
end
|
10
|
+
|
11
|
+
def is_round?( line )
|
12
|
+
## note: =~ return nil if not match found, and 0,1, etc for match
|
13
|
+
(line =~ SportDb.lang.regex_round) != nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def is_knockout_round?( line )
|
17
|
+
|
18
|
+
## todo: check for adding ignore case for regex (e.g. 1st leg/1st Leg)
|
19
|
+
|
20
|
+
if line =~ SportDb.lang.regex_leg1
|
21
|
+
logger.debug " two leg knockout; skip knockout flag on first leg"
|
22
|
+
false
|
23
|
+
elsif line =~ SportDb.lang.regex_knockout_round
|
24
|
+
logger.debug " setting knockout flag to true"
|
25
|
+
true
|
26
|
+
elsif line =~ /K\.O\.|K\.o\.|Knockout/
|
27
|
+
## NB: add two language independent markers, that is, K.O. and Knockout
|
28
|
+
logger.debug " setting knockout flag to true (lang independent marker)"
|
29
|
+
true
|
30
|
+
else
|
31
|
+
false
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
##
|
37
|
+
## fix/todo: check that [ROUND.TITLE2] and friends do NOT use pipes (|)
|
38
|
+
## change all pipes (|) to dot (.)
|
39
|
+
## - pipes get used for def markers!!!
|
40
|
+
|
41
|
+
def find_round_header_title2!( line )
|
42
|
+
## todo/fix:
|
43
|
+
## cleanup method
|
44
|
+
## use buf.index( '//' ) to split string (see found_round_def)
|
45
|
+
## why? simpler why not?
|
46
|
+
## - do we currently allow groups if title2 present? add example if it works?
|
47
|
+
|
48
|
+
|
49
|
+
# assume everything after // is title2 - strip off leading n trailing whitespaces
|
50
|
+
regex = /\/{2,}\s*(.+)\s*$/
|
51
|
+
if line =~ regex
|
52
|
+
logger.debug " title2: >#{$1}<"
|
53
|
+
|
54
|
+
line.sub!( regex, '[ROUND.TITLE2]' )
|
55
|
+
return $1
|
56
|
+
else
|
57
|
+
return nil # no round title2 found (title2 is optional)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
def find_round_header_title!( line )
|
63
|
+
# assume everything left is the round title
|
64
|
+
# extract all other items first (round title2, round pos, group title n pos, etc.)
|
65
|
+
|
66
|
+
## todo/fix:
|
67
|
+
## cleanup method
|
68
|
+
## use buf.index( '//' ) to split string (see found_round_def)
|
69
|
+
## why? simpler why not?
|
70
|
+
## - do we currently allow groups if title2 present? add example if it works?
|
71
|
+
|
72
|
+
buf = line.dup
|
73
|
+
logger.debug " find_round_header_title! line-before: >>#{buf}<<"
|
74
|
+
|
75
|
+
buf.gsub!( /\[[^\]]+\]/, '' ) # e.g. remove [ROUND.POS], [ROUND.TITLE2], [GROUP.TITLE+POS] etc.
|
76
|
+
buf.sub!( /\s+[\/\-]{1,}\s+$/, '' ) # remove optional trailing / or / chars (left over from group)
|
77
|
+
buf.strip! # remove leading and trailing whitespace
|
78
|
+
|
79
|
+
logger.debug " find_round_title! line-after: >>#{buf}<<"
|
80
|
+
|
81
|
+
### bingo - assume what's left is the round title
|
82
|
+
|
83
|
+
logger.debug " title: >>#{buf}<<"
|
84
|
+
line.sub!( buf, '[ROUND.TITLE]' )
|
85
|
+
|
86
|
+
buf
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
def find_round_def_title!( line )
|
91
|
+
# assume everything before pipe (\) is the round title
|
92
|
+
# strip [ROUND.POS], todo:?? [ROUND.TITLE2]
|
93
|
+
|
94
|
+
# todo/fix: add title2 w/ // or / why? why not?
|
95
|
+
# -- strip / or / chars
|
96
|
+
|
97
|
+
buf = line.dup
|
98
|
+
logger.debug " find_round_def_title! line-before: >>#{buf}<<"
|
99
|
+
|
100
|
+
## cut-off everything after (including) pipe (|)
|
101
|
+
buf = buf[ 0...buf.index('|') ]
|
102
|
+
|
103
|
+
# e.g. remove [ROUND.POS], [ROUND.TITLE2], [GROUP.TITLE+POS] etc.
|
104
|
+
buf.gsub!( /\[[^\]]+\]/, '' ) ## fix: use helper for (re)use e.g. remove_match_placeholder/marker or similar?
|
105
|
+
# remove leading and trailing whitespace
|
106
|
+
buf.strip!
|
107
|
+
|
108
|
+
logger.debug " find_round_def_title! line-after: >>#{buf}<<"
|
109
|
+
|
110
|
+
logger.debug " title: >>#{buf}<<"
|
111
|
+
line.sub!( buf, '[ROUND.TITLE]' )
|
112
|
+
|
113
|
+
buf
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
def find_round_pos!( line )
|
118
|
+
# pass #1) extract optional round pos from line
|
119
|
+
# e.g. (1) - must start line
|
120
|
+
regex_pos = /^[ \t]*\((\d{1,3})\)[ \t]+/
|
121
|
+
|
122
|
+
# pass #2) find free standing number e.g. Matchday 3 or Round 5 or 3. Spieltag etc.
|
123
|
+
# note: /\b(\d{1,3})\b/
|
124
|
+
# will match -12
|
125
|
+
# thus, use space required - will NOT match -2 e.g. Group-2 Play-off
|
126
|
+
# note: allow 1. Runde n
|
127
|
+
# 1^ Giornata
|
128
|
+
regex_num = /(?:^|\s)(\d{1,3})(?:[.\^\s]|$)/
|
129
|
+
|
130
|
+
if line =~ regex_pos
|
131
|
+
logger.debug " pos: >#{$1}<"
|
132
|
+
|
133
|
+
line.sub!( regex_pos, '[ROUND.POS] ' ) ## NB: add back trailing space that got swallowed w/ regex -> [ \t]+
|
134
|
+
return $1.to_i
|
135
|
+
elsif line =~ regex_num
|
136
|
+
## assume number in title is pos (e.g. Jornada 3, 3 Runde etc.)
|
137
|
+
## NB: do NOT remove pos from string (will get removed by round title)
|
138
|
+
|
139
|
+
num = $1.to_i # note: clone capture; keep a copy (another regex follows; will redefine $1)
|
140
|
+
|
141
|
+
#### fix:
|
142
|
+
# use/make keywords required
|
143
|
+
# e.g. Round of 16 -> should NOT match 16!
|
144
|
+
# Spiel um Platz 3 (or 5) etc -> should NOT match 3!
|
145
|
+
# Round 16 - ok
|
146
|
+
# thus, check for required keywords
|
147
|
+
|
148
|
+
## quick hack for round of 16
|
149
|
+
# todo: mask match e.g. Round of xxx ... and try again - might include something
|
150
|
+
# reuse pattern for Group XX Replays for example
|
151
|
+
if line =~ /^\s*Round of \d{1,3}\b/
|
152
|
+
return nil
|
153
|
+
end
|
154
|
+
|
155
|
+
logger.debug " pos: >#{num}<"
|
156
|
+
return num
|
157
|
+
else
|
158
|
+
## fix: add logger.warn no round pos found in line
|
159
|
+
return nil
|
160
|
+
end
|
161
|
+
end # method find_round_pos!
|
162
|
+
|
163
|
+
|
164
|
+
end # module FixtureHelpers
|
165
|
+
end # module SportDb
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module SportDb
|
4
|
+
module FixtureHelpers
|
5
|
+
|
6
|
+
|
7
|
+
def find_scores!( line, opts={} )
|
8
|
+
# note: always call after find_dates !!!
|
9
|
+
# scores match date-like patterns!! e.g. 10-11 or 10:00 etc.
|
10
|
+
# -- note: score might have two digits too
|
11
|
+
|
12
|
+
finder = ScoresFinder.new
|
13
|
+
finder.find!( line, opts )
|
14
|
+
end
|
15
|
+
|
16
|
+
end # module FixtureHelpers
|
17
|
+
end # module SportDb
|