sportdb-market 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,9 +22,9 @@ class Reader
22
22
 
23
23
  puts "*** parsing data '#{name}' (#{path})..."
24
24
 
25
- code = File.read_utf8( path )
25
+ reader = LineReader.new( logger, path )
26
26
 
27
- load_worker( service_key, event_key, code )
27
+ load_worker( service_key, event_key, reader )
28
28
 
29
29
  Prop.create!( key: "db.#{fixture_name_to_prop_key(name)}.version", value: "file.txt.#{File.mtime(path).strftime('%Y.%m.%d')}" )
30
30
  end
@@ -34,30 +34,17 @@ class Reader
34
34
 
35
35
  puts "*** parsing data '#{name}' (#{path})..."
36
36
 
37
- code = File.read_utf8( path )
37
+ reader = LineReader.new( logger, path )
38
38
 
39
- load_worker( service_key, event_key, code )
39
+ load_worker( service_key, event_key, reader )
40
40
 
41
41
  Prop.create!( key: "db.#{fixture_name_to_prop_key(name)}.version", value: "sport.market.txt.#{SportDB::Market::VERSION}" )
42
42
  end
43
43
 
44
44
  private
45
45
 
46
- ##
47
- # fix/todo: share helper w/ other readers
48
-
49
- # helper
50
- # change at/2012_13/bl to at.2012/13.bl
51
- # or quali_2012_13_europe_c to quali.2012/13.europe.c
52
-
53
- def fixture_name_to_prop_key( name )
54
- prop_key = name.gsub( '/', '.' )
55
- prop_key = prop_key.gsub( /(\d{4})_(\d{2})/, '\1/\2' ) # 2012_13 => 2012/13
56
- prop_key = prop_key.gsub( '_', '.' )
57
- prop_key
58
- end
59
46
 
60
- def load_worker( service_key, event_key, data )
47
+ def load_worker( service_key, event_key, reader )
61
48
 
62
49
  ## assume active activerecord connection
63
50
  ##
@@ -70,30 +57,14 @@ private
70
57
 
71
58
  @known_teams = @event.known_teams_table
72
59
 
73
- parse_quotes( data )
60
+ parse_quotes( reader )
74
61
 
75
62
  end # method load
76
63
 
77
64
 
78
- def is_round?( line )
79
- line =~ /Spieltag|Runde/
80
- end
81
-
82
- def find_round_pos!( line )
83
- regex = /\b(\d+)\b/
84
-
85
- if line =~ regex
86
- value = $1.to_i
87
- puts " pos: >#{value}<"
88
-
89
- line.sub!( regex, '[POS]' )
65
+ include SportDB::FixtureHelpers
66
+
90
67
 
91
- return value
92
- else
93
- return nil
94
- end
95
- end
96
-
97
68
  def find_quotes!( line )
98
69
  # extract quotes triplet from line
99
70
  # and return it
@@ -136,74 +107,10 @@ private
136
107
  end
137
108
 
138
109
 
139
- def find_team_worker!( line, index )
140
- regex = /@@oo([^@]+?)oo@@/ # e.g. everything in @@ .... @@ (use non-greedy +? plus all chars but not @, that is [^@])
141
-
142
- if line =~ regex
143
- value = "#{$1}"
144
- puts " team#{index}: >#{value}<"
145
-
146
- line.sub!( regex, "[TEAM#{index}]" )
147
-
148
- return $1
149
- else
150
- return nil
151
- end
152
- end
153
-
154
- def find_team1!( line )
155
- find_team_worker!( line, 1 )
156
- end
157
-
158
- def find_team2!( line )
159
- find_team_worker!( line, 2 )
160
- end
161
-
162
-
163
- def match_team_worker!( line, key, values )
164
- values.each do |value|
165
-
166
- ## nb: \b does NOT include space or newline for word boundry (only alphanums e.g. a-z0-9)
167
- ## (thus add it, allows match for Benfica Lis. for example - note . at the end)
168
- regex = /\b#{value}(\b| |\t|$)/ # wrap with world boundry (e.g. match only whole words e.g. not wac in wacker)
169
- if line =~ regex
170
- puts " match for team >#{key}< >#{value}<"
171
- # make sure @@oo{key}oo@@ doesn't match itself with other key e.g. wacker, wac, etc.
172
- line.sub!( regex, "@@oo#{key}oo@@ " ) # NB: add one space char at end
173
- return true # break out after first match (do NOT continue)
174
- end
175
- end
176
- return false
177
- end
178
-
179
- def match_teams!( line )
180
- @known_teams.each do |rec|
181
- key = rec[0]
182
- values = rec[1]
183
- match_team_worker!( line, key, values )
184
- end # each known_teams
185
- end # method translate_teams!
186
-
187
-
188
- def parse_quotes( data )
110
+ def parse_quotes( reader )
189
111
 
190
- data.each_line do |line|
112
+ reader.each_line do |line|
191
113
 
192
- if line =~ /^\s*#/
193
- # skip komments and do NOT copy to result (keep comments secret!)
194
- logger.debug 'skipping comment line'
195
- next
196
- end
197
-
198
- if line =~ /^\s*$/
199
- # kommentar oder leerzeile überspringen
200
- logger.debug 'skipping blank line'
201
- next
202
- end
203
-
204
- # remove leading and trailing whitespace
205
- line = line.strip
206
-
207
114
  if is_round?( line )
208
115
  puts "parsing round line: >#{line}<"
209
116
  pos = find_round_pos!( line )
@@ -260,7 +167,7 @@ private
260
167
 
261
168
  quote.update_attributes!( quote_attribs )
262
169
  end
263
- end # oldlines.each
170
+ end # each lines
264
171
 
265
172
  end # method parse_quotes
266
173
 
@@ -2,5 +2,5 @@
2
2
  module SportDB ; end # forward reference (for hoe require)
3
3
 
4
4
  module SportDB::Market
5
- VERSION = '0.1.4'
5
+ VERSION = '0.2.0'
6
6
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sportdb-market
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 4
10
- version: 0.1.4
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Gerald Bauer
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-11-20 00:00:00 Z
18
+ date: 2012-11-21 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rdoc