sportdb 1.8.3 → 1.8.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,91 @@
1
+ # encoding: utf-8
2
+
3
+ module SportDb
4
+ module FixtureHelpers
5
+
6
+
7
+ def find_scores!( line )
8
+
9
+ # note: always call after find_dates !!!
10
+ # scores match date-like patterns!! e.g. 10-11 or 10:00 etc.
11
+ # -- note: score might have two digits too
12
+
13
+ ### fix: depending on language allow 1:1 or 1-1
14
+ ## do NOT allow mix and match
15
+ ## e.g. default to en is 1-1
16
+ ## de is 1:1 etc.
17
+
18
+
19
+ # extract score from line
20
+ # and return it
21
+ # NB: side effect - removes date from line string
22
+
23
+ # note: regex should NOT match regex extra time or penalty
24
+ # thus, we do NOT any longer allow spaces for now between
25
+ # score and marker (e.g. nV,iE, etc.)
26
+
27
+ # e.g. 1:2 or 0:2 or 3:3 // 1-1 or 0-2 or 3-3
28
+ regex = /\b(\d{1,2})[:\-](\d{1,2})\b/
29
+
30
+ ## todo: add/allow english markers e.g. aet ??
31
+
32
+ ## fix: use case insansitive flag instead e.g. /i
33
+ # instead of [nN] etc.
34
+
35
+ # e.g. 1:2nV => after extra time a.e.t
36
+ regex_et = /\b(\d{1,2})[:\-](\d{1,2})[nN][vV]\b/
37
+
38
+ # e.g. 5:4iE => penalty / after penalty a.p
39
+ regex_p = /\b(\d{1,2})[:\-](\d{1,2})[iI][eE]\b/
40
+
41
+ scores = []
42
+
43
+ ## todo: how to handle game w/o extra time
44
+ # but w/ optional penalty ??? e.g. used in copa liberatores, for example
45
+ # retrun 0,0 or nil,nil for extra time score ?? or -1, -1 ??
46
+ # for now use nil,nil
47
+
48
+ if line =~ regex
49
+ logger.debug " score: >#{$1}-#{$2}<"
50
+
51
+ line.sub!( regex, '[SCORE]' )
52
+
53
+ scores << $1.to_i
54
+ scores << $2.to_i
55
+ end
56
+
57
+ ## todo:
58
+ ## reverse matching order ??? allows us to support spaces for nV and iE
59
+ ## why? why not??
60
+
61
+ if line =~ regex_et
62
+ logger.debug " score.et: >#{$1}-#{$2}<"
63
+
64
+ line.sub!( regex_et, '[SCORE.ET]' )
65
+
66
+ ## check scores empty? - fill with nil,nil
67
+ scores += [nil,nil] if scores.size == 0
68
+
69
+ scores << $1.to_i
70
+ scores << $2.to_i
71
+ end
72
+
73
+ if line =~ regex_p
74
+ logger.debug " score.p: >#{$1}-#{$2}<"
75
+
76
+ line.sub!( regex_p, '[SCORE.P]' )
77
+
78
+ ## check scores empty? - fill with nil,nil
79
+ scores += [nil,nil] if scores.size == 0
80
+ scores += [nil,nil] if scores.size == 2
81
+
82
+ scores << $1.to_i
83
+ scores << $2.to_i
84
+ end
85
+ scores
86
+ end # methdod find_scores!
87
+
88
+
89
+ end # module FixtureHelpers
90
+ end # module SportDb
91
+
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ module SportDb
4
+ module FixtureHelpers
5
+
6
+
7
+ def find_teams!( line ) # NB: returns an array - note: plural! (teamsss)
8
+ TextUtils.find_keys_for!( 'team', line )
9
+ end
10
+
11
+ def find_team!( line ) # NB: returns key (string or nil)
12
+ TextUtils.find_key_for!( 'team', line )
13
+ end
14
+
15
+ ## todo: check if find_team1 gets used? if not remove it!! use find_teams!
16
+ def find_team1!( line )
17
+ TextUtils.find_key_for!( 'team1', line )
18
+ end
19
+
20
+ def find_team2!( line )
21
+ TextUtils.find_key_for!( 'team2', line )
22
+ end
23
+
24
+ ## todo/fix: pass in known_teams as a parameter? why? why not?
25
+
26
+ def map_teams!( line )
27
+ TextUtils.map_titles_for!( 'team', line, @known_teams )
28
+ end
29
+
30
+ def map_team!( line ) # alias map_teams!
31
+ map_teams!( line )
32
+ end
33
+
34
+
35
+
36
+ ## depreciated methods - use map_
37
+ def match_teams!( line ) ## fix: rename to map_teams!! - remove match_teams!
38
+ ## todo: issue depreciated warning
39
+ map_teams!( line )
40
+ end # method match_teams!
41
+
42
+ def match_track!( line ) ## fix: rename to map_track!!!
43
+ ## todo: issue depreciated warning
44
+ map_track!( line )
45
+ end # method match_tracks!
46
+
47
+
48
+ end # module FixtureHelpers
49
+ end # module SportDb
@@ -1,6 +1,6 @@
1
1
 
2
2
  module SportDb
3
- VERSION = '1.8.3'
3
+ VERSION = '1.8.5'
4
4
  end
5
5
 
6
6
 
@@ -8,3 +8,4 @@ end
8
8
  # fix: remove old alias for SportDb
9
9
 
10
10
  SportDB = SportDb
11
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sportdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.3
4
+ version: 1.8.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-14 00:00:00.000000000 Z
12
+ date: 2014-02-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: worlddb
16
- requirement: &18821544 !ruby/object:Gem::Requirement
16
+ requirement: &20942556 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1.7'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *18821544
24
+ version_requirements: *20942556
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: fetcher
27
- requirement: &18819840 !ruby/object:Gem::Requirement
27
+ requirement: &20939616 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0.3'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *18819840
35
+ version_requirements: *20939616
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: gli
38
- requirement: &18818232 !ruby/object:Gem::Requirement
38
+ requirement: &20837484 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 2.5.6
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *18818232
46
+ version_requirements: *20837484
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rdoc
49
- requirement: &18832080 !ruby/object:Gem::Requirement
49
+ requirement: &20834256 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '4.0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *18832080
57
+ version_requirements: *20834256
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: hoe
60
- requirement: &18826716 !ruby/object:Gem::Requirement
60
+ requirement: &20832636 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '3.7'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *18826716
68
+ version_requirements: *20832636
69
69
  description: sportdb - sport.db command line tool
70
70
  email: opensport@googlegroups.com
71
71
  executables:
@@ -153,9 +153,15 @@ files:
153
153
  - lib/sportdb/service/views/index.erb
154
154
  - lib/sportdb/service/views/layout.erb
155
155
  - lib/sportdb/stats.rb
156
- - lib/sportdb/title.rb
157
156
  - lib/sportdb/updater.rb
158
157
  - lib/sportdb/utils.rb
158
+ - lib/sportdb/utils_date.rb
159
+ - lib/sportdb/utils_group.rb
160
+ - lib/sportdb/utils_map.rb
161
+ - lib/sportdb/utils_record.rb
162
+ - lib/sportdb/utils_round.rb
163
+ - lib/sportdb/utils_scores.rb
164
+ - lib/sportdb/utils_teams.rb
159
165
  - lib/sportdb/version.rb
160
166
  - test/helper.rb
161
167
  - test/test_changes.rb
data/lib/sportdb/title.rb DELETED
@@ -1,146 +0,0 @@
1
- # encoding: utf-8
2
-
3
- ################
4
- # todo: move module to textutils!!!
5
-
6
- ### fix: move to textutils??
7
-
8
-
9
- ## todo: rename to TitleHelpers? TitleMatcher? TitleMapper? TitleMapping? TitleMappings? TitleFinder? TitleHelpers?
10
- # or rename to KeyMapping?, KeyMapper?, KeyTable? etc.
11
-
12
-
13
- module TextUtils::TitleTable
14
-
15
-
16
- def build_title_table_for( records )
17
- ## build known tracks table w/ synonyms e.g.
18
- #
19
- # [[ 'wolfsbrug', [ 'VfL Wolfsburg' ]],
20
- # [ 'augsburg', [ 'FC Augsburg', 'Augi2', 'Augi3' ]],
21
- # [ 'stuttgart', [ 'VfB Stuttgart' ]] ]
22
-
23
- known_titles = []
24
-
25
- records.each_with_index do |rec,index|
26
-
27
- title_candidates = []
28
- title_candidates << rec.title
29
-
30
- title_candidates += rec.synonyms.split('|') if rec.synonyms.present?
31
-
32
-
33
- ## check if title includes subtitle e.g. Grand Prix Japan (Suzuka Circuit)
34
- # make subtitle optional by adding title w/o subtitle e.g. Grand Prix Japan
35
-
36
- titles = []
37
- title_candidates.each do |t|
38
- titles << t
39
- if t =~ /\(.+\)/
40
- extra_title = t.gsub( /\(.+\)/, '' ) # remove/delete subtitles
41
- extra_title.strip! # strip leading n trailing withspaces too!
42
- titles << extra_title
43
- end
44
- end
45
-
46
-
47
- ## NB: sort here by length (largest goes first - best match)
48
- # exclude code and key (key should always go last)
49
- titles = titles.sort { |left,right| right.length <=> left.length }
50
-
51
- ## escape for regex plus allow subs for special chars/accents
52
- titles = titles.map { |title| TextUtils.title_esc_regex( title ) }
53
-
54
- ## NB: only include code field - if defined
55
- titles << rec.code if rec.respond_to?(:code) && rec.code.present?
56
-
57
- known_titles << [ rec.key, titles ]
58
-
59
- ### fix: use plain logger
60
- LogUtils::Logger.root.debug " #{rec.class.name}[#{index+1}] #{rec.key} >#{titles.join('|')}<"
61
- end
62
-
63
- known_titles
64
- end
65
-
66
-
67
-
68
- def find_key_for!( name, line )
69
- regex = /@@oo([^@]+?)oo@@/ # e.g. everything in @@ .... @@ (use non-greedy +? plus all chars but not @, that is [^@])
70
-
71
- upcase_name = name.upcase
72
- downcase_name = name.downcase
73
-
74
- if line =~ regex
75
- value = "#{$1}"
76
- ### fix: use plain logger
77
- LogUtils::Logger.root.debug " #{downcase_name}: >#{value}<"
78
-
79
- line.sub!( regex, "[#{upcase_name}]" )
80
-
81
- return $1
82
- else
83
- return nil
84
- end
85
- end
86
-
87
-
88
- def find_keys_for!( name, line ) # NB: keys (plural!) - will return array
89
- counter = 1
90
- keys = []
91
-
92
- downcase_name = name.downcase
93
-
94
- key = find_key_for!( "#{downcase_name}#{counter}", line )
95
- while key.present?
96
- keys << key
97
- counter += 1
98
- key = find_key_for!( "#{downcase_name}#{counter}", line )
99
- end
100
-
101
- keys
102
- end
103
-
104
-
105
- def map_titles_for!( name, line, title_table )
106
- title_table.each do |rec|
107
- key = rec[0]
108
- values = rec[1]
109
- map_title_worker_for!( name, line, key, values )
110
- end
111
- end
112
-
113
-
114
- def map_title_worker_for!( name, line, key, values )
115
-
116
- downcase_name = name.downcase
117
-
118
- values.each do |value|
119
- ## nb: \b does NOT include space or newline for word boundry (only alphanums e.g. a-z0-9)
120
- ## (thus add it, allows match for Benfica Lis. for example - note . at the end)
121
-
122
- ## check add $ e.g. (\b| |\t|$) does this work? - check w/ Benfica Lis.$
123
- regex = /\b#{value}(\b| |\t|$)/ # wrap with world boundry (e.g. match only whole words e.g. not wac in wacker)
124
- if line =~ regex
125
- ### fix: use plain logger
126
- LogUtils::Logger.root.debug " match for #{downcase_name} >#{key}< >#{value}<"
127
- # make sure @@oo{key}oo@@ doesn't match itself with other key e.g. wacker, wac, etc.
128
- line.sub!( regex, "@@oo#{key}oo@@ " ) # NB: add one space char at end
129
- return true # break out after first match (do NOT continue)
130
- end
131
- end
132
- return false
133
- end
134
-
135
-
136
-
137
- end # module TextUtils::TitleTable
138
-
139
-
140
-
141
- ## auto-include methods
142
-
143
- module TextUtils
144
- # make helpers available as class methods e.g. TextUtils.convert_unicode_dashes_to_plain_ascii
145
- extend TitleTable # lets us use TextUtils.build_title_table_for etc.
146
- end