sportdb 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -23,7 +23,7 @@ Hoe.spec 'sportdb' do
23
23
  # self.history_file = 'History.md'
24
24
 
25
25
  self.extra_deps = [
26
- ['worlddb', '~> 1.1.0'], # NB: worlddb already includes
26
+ ['worlddb', '~> 1.2.0'], # NB: worlddb already includes
27
27
  # - commander
28
28
  # - logutils
29
29
  # - textutils
@@ -4,6 +4,7 @@ require 'commander/import'
4
4
 
5
5
  # our own code / additional for cli only
6
6
 
7
+ require 'logutils/db'
7
8
  require 'sportdb/cli/opts'
8
9
 
9
10
 
@@ -60,6 +61,8 @@ def connect_to_db( options )
60
61
  pp db_config
61
62
 
62
63
  ActiveRecord::Base.establish_connection( db_config )
64
+
65
+ LogDb.setup # start logging to db
63
66
  end
64
67
 
65
68
 
data/lib/sportdb/lang.rb CHANGED
@@ -4,7 +4,11 @@ module SportDB
4
4
 
5
5
  class Lang
6
6
 
7
- def initialize( logger=nil )
7
+ def logger
8
+ @logger ||= LogUtils[ self ]
9
+ end
10
+
11
+ def initialize
8
12
 
9
13
  @lang = 'en' # make default lang english/en
10
14
 
@@ -37,11 +41,11 @@ class Lang
37
41
  attr_reader :lang
38
42
 
39
43
  def lang=(value)
40
- puts "setting lang to #{value}"
44
+ logger.debug "setting lang to #{value}"
41
45
 
42
46
  if @lang != value
43
47
  # reset cached values on language change
44
- puts "reseting cached lang values (lang changed from #{@lang} to #{value})"
48
+ logger.debug "reseting cached lang values (lang changed from #{@lang} to #{value})"
45
49
 
46
50
  @group = nil
47
51
  @round = nil
@@ -184,7 +188,7 @@ private
184
188
  key = key_wild.to_s.strip
185
189
  values = values_wild.to_s.strip
186
190
 
187
- puts "processing key >>#{key}<< with words >>#{values}<<"
191
+ logger.debug "processing key >>#{key}<< with words >>#{values}<<"
188
192
 
189
193
  ary += values.split('|')
190
194
  end
@@ -196,8 +200,11 @@ end # class Lang
196
200
 
197
201
  class LangChecker
198
202
 
199
- def initialize( logger=nil )
200
- ## add logger here
203
+ def logger
204
+ @logger ||= LogUtils[ self ]
205
+ end
206
+
207
+ def initialize
201
208
  end
202
209
 
203
210
  def analyze( name, include_path )
@@ -205,7 +212,7 @@ class LangChecker
205
212
 
206
213
  path = "#{include_path}/#{name}.txt"
207
214
 
208
- puts "*** parsing data '#{name}' (#{path})..."
215
+ logger.info "parsing data '#{name}' (#{path})..."
209
216
 
210
217
  text = File.read_utf8( path )
211
218
 
@@ -227,11 +234,11 @@ class LangChecker
227
234
 
228
235
  # dump stats
229
236
 
230
- puts "****************************************"
237
+ logger.info "****************************************"
231
238
  lang_counts.each_with_index do |item,index|
232
239
  ## e.g. 1. en: 20 words
233
240
  ## 2. de: 2 words
234
- puts "#{index+1}. #{item[0]}: #{item[1]}"
241
+ logger.info "#{index+1}. #{item[0]}: #{item[1]}"
235
242
  end
236
243
 
237
244
  ## return lang code w/ highest count
@@ -244,7 +251,7 @@ private
244
251
  pos = text.index( word )
245
252
  while pos.nil? == false
246
253
  count += 1
247
- puts "bingo - found >>#{word}<< on pos #{pos}, count: #{count}"
254
+ logger.debug "bingo - found >>#{word}<< on pos #{pos}, count: #{count}"
248
255
  ### todo: check if pos+word.length/size needs +1 or similar
249
256
  pos = text.index( word, pos+word.length)
250
257
  end
@@ -4,17 +4,18 @@ module SportDB
4
4
 
5
5
  class Reader
6
6
 
7
+ def logger
8
+ @logger ||= LogUtils[ self ]
9
+ end
10
+
7
11
  ## make models available in sportdb module by default with namespace
8
12
  # e.g. lets you use Team instead of Models::Team
9
13
  include SportDB::Models
10
14
 
11
15
 
12
- def initialize( opts={} )
13
- @logger = LogUtils::Logger.new
16
+ def initialize
14
17
  end
15
18
 
16
- attr_reader :logger
17
-
18
19
  def load_setup( setup, include_path )
19
20
  ary = load_fixture_setup( setup, include_path )
20
21
  load( ary, include_path )
@@ -136,7 +137,7 @@ class Reader
136
137
 
137
138
  logger.info "parsing data '#{name}' (#{path})..."
138
139
 
139
- reader = ValuesReader.new( logger, path, more_values )
140
+ reader = ValuesReader.new( path, more_values )
140
141
 
141
142
  load_leagues_worker( reader )
142
143
 
@@ -151,7 +152,7 @@ class Reader
151
152
 
152
153
  puts "*** parsing data '#{name}' (#{path})..."
153
154
 
154
- reader = HashReader.new( logger, path )
155
+ reader = HashReader.new( path )
155
156
 
156
157
  reader.each_typed do |key, value|
157
158
 
@@ -169,16 +170,16 @@ class Reader
169
170
 
170
171
  ## check if it exists
171
172
  if season.present?
172
- puts "*** update season #{season.id}-#{season.key}:"
173
+ logger.debug "update season #{season.id}-#{season.key}:"
173
174
  else
174
- puts "*** create season:"
175
+ logger.debug "create season:"
175
176
  season = Season.new
176
177
  season_attribs[ :key ] = item.to_s.strip
177
178
  end
178
179
 
179
180
  season_attribs[:title] = item.to_s.strip
180
181
 
181
- puts season_attribs.to_json
182
+ logger.debug season_attribs.to_json
182
183
 
183
184
  season.update_attributes!( season_attribs )
184
185
  end
@@ -201,7 +202,7 @@ class Reader
201
202
 
202
203
  logger.info "parsing data '#{name}' (#{path})..."
203
204
 
204
- reader = HashReader.new( logger, path )
205
+ reader = HashReader.new( path )
205
206
 
206
207
  event_attribs = {}
207
208
 
@@ -274,7 +275,7 @@ class Reader
274
275
  event = Event.new
275
276
  end
276
277
 
277
- puts event_attribs.to_json
278
+ logger.debug event_attribs.to_json
278
279
 
279
280
  event.update_attributes!( event_attribs )
280
281
 
@@ -286,7 +287,7 @@ class Reader
286
287
  def load_fixtures_from_string( event_key, text ) # load from string (e.g. passed in via web form)
287
288
 
288
289
  ## todo/fix: move code into LineReader e.g. use LineReader.fromString() - why? why not?
289
- reader = StringLineReader.new( logger, text )
290
+ reader = StringLineReader.new( text )
290
291
 
291
292
  load_fixtures_worker( event_key, reader )
292
293
 
@@ -302,7 +303,7 @@ class Reader
302
303
 
303
304
  SportDB.lang.lang = LangChecker.new.analyze( name, include_path )
304
305
 
305
- reader = LineReader.new( logger, path )
306
+ reader = LineReader.new( path )
306
307
 
307
308
  load_fixtures_worker( event_key, reader )
308
309
 
@@ -316,7 +317,7 @@ class Reader
316
317
 
317
318
  puts "*** parsing data '#{name}' (#{path})..."
318
319
 
319
- reader = ValuesReader.new( logger, path, more_values )
320
+ reader = ValuesReader.new( path, more_values )
320
321
 
321
322
  load_teams_worker( reader )
322
323
 
@@ -456,7 +457,7 @@ private
456
457
  })
457
458
  end
458
459
 
459
- puts group_attribs.to_json
460
+ logger.debug group_attribs.to_json
460
461
 
461
462
  @group.update_attributes!( group_attribs )
462
463
 
@@ -495,9 +496,9 @@ private
495
496
 
496
497
  @round = Round.find_by_event_id_and_pos( @event.id, pos )
497
498
  if @round.present?
498
- puts "*** update round #{@round.id}:"
499
+ logger.debug "update round #{@round.id}:"
499
500
  else
500
- puts "*** create round:"
501
+ logger.debug "create round:"
501
502
  @round = Round.new
502
503
 
503
504
  round_attribs = round_attribs.merge( {
@@ -508,7 +509,7 @@ private
508
509
  })
509
510
  end
510
511
 
511
- puts round_attribs.to_json
512
+ logger.debug round_attribs.to_json
512
513
 
513
514
  @round.update_attributes!( round_attribs )
514
515
 
@@ -517,7 +518,7 @@ private
517
518
  end
518
519
 
519
520
  def parse_game( line )
520
- puts "parsing game (fixture) line: >#{line}<"
521
+ logger.debug "parsing game (fixture) line: >#{line}<"
521
522
 
522
523
  pos = find_game_pos!( line )
523
524
 
@@ -528,7 +529,7 @@ private
528
529
  date = find_date!( line )
529
530
  scores = find_scores!( line )
530
531
 
531
- puts " line: >#{line}<"
532
+ logger.debug " line: >#{line}<"
532
533
 
533
534
 
534
535
  ### todo: cache team lookups in hash?
@@ -557,9 +558,9 @@ private
557
558
  game_attribs[ :pos ] = pos if pos.present?
558
559
 
559
560
  if game.present?
560
- puts "*** update game #{game.id}:"
561
+ logger.debug "update game #{game.id}:"
561
562
  else
562
- puts "*** create game:"
563
+ logger.debug "create game:"
563
564
  game = Game.new
564
565
 
565
566
  more_game_attribs = {
@@ -575,7 +576,7 @@ private
575
576
  game_attribs = game_attribs.merge( more_game_attribs )
576
577
  end
577
578
 
578
- puts game_attribs.to_json
579
+ logger.debug game_attribs.to_json
579
580
 
580
581
  game.update_attributes!( game_attribs )
581
582
  end
@@ -594,7 +595,7 @@ private
594
595
  end # lines.each
595
596
 
596
597
  @patch_rounds.each do |k,v|
597
- puts "*** patch start_at/end_at date for round #{k}:"
598
+ logger.debug "patch start_at/end_at date for round #{k}:"
598
599
  round = Round.find( k )
599
600
  games = round.games.order( 'play_at asc' ).all
600
601
 
@@ -611,7 +612,7 @@ private
611
612
  round_attribs[:start_at] = games[0].play_at
612
613
  round_attribs[:end_at ] = games[-1].play_at
613
614
 
614
- puts round_attribs.to_json
615
+ logger.debug round_attribs.to_json
615
616
  round.update_attributes!( round_attribs )
616
617
  end
617
618
 
data/lib/sportdb/utils.rb CHANGED
@@ -19,14 +19,14 @@ module SportDB::FixtureHelpers
19
19
  ## todo: check for adding ignore case for regex (e.g. 1st leg/1st Leg)
20
20
 
21
21
  if line =~ SportDB.lang.regex_leg1
22
- puts " two leg knockout; skip knockout flag on first leg"
22
+ logger.debug " two leg knockout; skip knockout flag on first leg"
23
23
  false
24
24
  elsif line =~ SportDB.lang.regex_knockout_round
25
- puts " setting knockout flag to true"
25
+ logger.debug " setting knockout flag to true"
26
26
  true
27
27
  elsif line =~ /K\.O\.|Knockout/
28
28
  ## NB: add two language independent markers, that is, K.O. and Knockout
29
- puts " setting knockout flag to true (lang independent marker)"
29
+ logger.debug " setting knockout flag to true (lang independent marker)"
30
30
  true
31
31
  else
32
32
  false
@@ -61,8 +61,8 @@ module SportDB::FixtureHelpers
61
61
 
62
62
  title = match[0]
63
63
 
64
- puts " title: >#{title}<"
65
- puts " pos: >#{pos}<"
64
+ logger.debug " title: >#{title}<"
65
+ logger.debug " pos: >#{pos}<"
66
66
 
67
67
  line.sub!( regex, '[GROUP|TITLE+POS]' )
68
68
 
@@ -81,7 +81,7 @@ module SportDB::FixtureHelpers
81
81
  # e.g. (1) - must start line
82
82
  regex = /^[ \t]*\((\d{1,3})\)[ \t]+/
83
83
  if line =~ regex
84
- puts " pos: >#{$1}<"
84
+ logger.debug " pos: >#{$1}<"
85
85
 
86
86
  line.sub!( regex, '[ROUND|POS] ' ) ## NB: add back trailing space that got swallowed w/ regex -> [ \t]+
87
87
  return $1.to_i
@@ -110,7 +110,7 @@ module SportDB::FixtureHelpers
110
110
 
111
111
  if line =~ regex
112
112
  value = $1.to_i
113
- puts " pos: >#{value}<"
113
+ logger.debug " pos: >#{value}<"
114
114
 
115
115
  line.sub!( regex, '[ROUND|POS]' )
116
116
 
@@ -139,7 +139,7 @@ module SportDB::FixtureHelpers
139
139
 
140
140
  if line =~ regex_db
141
141
  value = "#{$1}-#{$2}-#{$3} #{$4}:#{$5}"
142
- puts " date: >#{value}<"
142
+ logger.debug " date: >#{value}<"
143
143
 
144
144
  ## todo: lets you configure year
145
145
  ## and time zone (e.g. cet, eet, utc, etc.)
@@ -149,14 +149,14 @@ module SportDB::FixtureHelpers
149
149
  return DateTime.strptime( value, '%Y-%m-%d %H:%M' )
150
150
  elsif line =~ regex_db2
151
151
  value = "#{$1}-#{$2}-#{$3} 12:00"
152
- puts " date: >#{value}<"
152
+ logger.debug " date: >#{value}<"
153
153
 
154
154
  line.sub!( regex_db2, '[DATE.DB2]' )
155
155
 
156
156
  return DateTime.strptime( value, '%Y-%m-%d %H:%M' )
157
157
  elsif line =~ regex_de2
158
158
  value = "#{$3}-#{$2}-#{$1} #{$4}:#{$5}"
159
- puts " date: >#{value}<"
159
+ logger.debug " date: >#{value}<"
160
160
 
161
161
  ## todo: lets you configure year
162
162
  ## and time zone (e.g. cet, eet, utc, etc.)
@@ -166,7 +166,7 @@ module SportDB::FixtureHelpers
166
166
  return DateTime.strptime( value, '%Y-%m-%d %H:%M' )
167
167
  elsif line =~ regex_de
168
168
  value = "2012-#{$2}-#{$1} #{$3}:#{$4}"
169
- puts " date: >#{value}<"
169
+ logger.debug " date: >#{value}<"
170
170
 
171
171
  ## todo: lets you configure year
172
172
  ## and time zone (e.g. cet, eet, utc, etc.)
@@ -188,7 +188,7 @@ module SportDB::FixtureHelpers
188
188
  # e.g. (1) - must start line
189
189
  regex = /^[ \t]*\((\d{1,3})\)[ \t]+/
190
190
  if line =~ regex
191
- puts " pos: >#{$1}<"
191
+ logger.debug " pos: >#{$1}<"
192
192
 
193
193
  line.sub!( regex, '[POS] ' )
194
194
  return $1.to_i
@@ -222,7 +222,7 @@ module SportDB::FixtureHelpers
222
222
  scores = []
223
223
 
224
224
  if line =~ regex
225
- puts " score: >#{$1}-#{$2}<"
225
+ logger.debug " score: >#{$1}-#{$2}<"
226
226
 
227
227
  line.sub!( regex, '[SCORE]' )
228
228
 
@@ -230,7 +230,7 @@ module SportDB::FixtureHelpers
230
230
  scores << $2.to_i
231
231
 
232
232
  if line =~ regex_ot
233
- puts " score.ot: >#{$1}-#{$2}<"
233
+ logger.debug " score.ot: >#{$1}-#{$2}<"
234
234
 
235
235
  line.sub!( regex_ot, '[SCORE.OT]' )
236
236
 
@@ -238,7 +238,7 @@ module SportDB::FixtureHelpers
238
238
  scores << $2.to_i
239
239
 
240
240
  if line =~ regex_p
241
- puts " score.p: >#{$1}-#{$2}<"
241
+ logger.debug " score.p: >#{$1}-#{$2}<"
242
242
 
243
243
  line.sub!( regex_p, '[SCORE.P]' )
244
244
 
@@ -256,7 +256,7 @@ module SportDB::FixtureHelpers
256
256
 
257
257
  if line =~ regex
258
258
  value = "#{$1}"
259
- puts " team#{index}: >#{value}<"
259
+ logger.debug " team#{index}: >#{value}<"
260
260
 
261
261
  line.sub!( regex, "[TEAM#{index}]" )
262
262
 
@@ -297,7 +297,7 @@ module SportDB::FixtureHelpers
297
297
  ## check add $ e.g. (\b| |\t|$) does this work? - check w/ Benfica Lis.$
298
298
  regex = /\b#{value}(\b| |\t|$)/ # wrap with world boundry (e.g. match only whole words e.g. not wac in wacker)
299
299
  if line =~ regex
300
- puts " match for team >#{key}< >#{value}<"
300
+ logger.debug " match for team >#{key}< >#{value}<"
301
301
  # make sure @@oo{key}oo@@ doesn't match itself with other key e.g. wacker, wac, etc.
302
302
  line.sub!( regex, "@@oo#{key}oo@@ " ) # NB: add one space char at end
303
303
  return true # break out after first match (do NOT continue)
@@ -317,4 +317,3 @@ module SportDB::FixtureHelpers
317
317
 
318
318
 
319
319
  end # module SportDB::FixtureHelpers
320
-
@@ -1,4 +1,4 @@
1
1
 
2
2
  module SportDB
3
- VERSION = '1.1.0'
3
+ VERSION = '1.2.0'
4
4
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sportdb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 1.1.0
10
+ version: 1.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: 2013-02-21 00:00:00 Z
18
+ date: 2013-02-22 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: worlddb
@@ -25,12 +25,12 @@ dependencies:
25
25
  requirements:
26
26
  - - ~>
27
27
  - !ruby/object:Gem::Version
28
- hash: 19
28
+ hash: 31
29
29
  segments:
30
30
  - 1
31
- - 1
31
+ - 2
32
32
  - 0
33
- version: 1.1.0
33
+ version: 1.2.0
34
34
  type: :runtime
35
35
  version_requirements: *id001
36
36
  - !ruby/object:Gem::Dependency