sportdb-formats 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 25a05ffd2370b2e9c8c24516e332e8c81b69ae2a
4
- data.tar.gz: 5a033c65a78d9313316098d75b5ea9b021946b5b
3
+ metadata.gz: 84244a1e794fcbc1fea7365921dab81a1e33b5b1
4
+ data.tar.gz: 916eac3f334d3e10b27b0852a2b4634b0f498677
5
5
  SHA512:
6
- metadata.gz: 3c3e031a037e67c819c582bf5fbe99c581f4d3120fe49dd3445cdfadf96b812cf47f86ac4c3c1ee52457fbe4c29e47df39ebd2e44732828dae414a26f04af568
7
- data.tar.gz: 4964b799f112e4f565f30e99325de611d38015e2f377d9a4abe8bc26f6ccc8c0cd718f5f24c1fe3bdc04ded097bf2095bdbf676c9b1eccc432160a5020b063d3
6
+ metadata.gz: 3a9d7d0616bd1f3f6dc08314ede6813392b00d622d32f5cf1b9309d9382e1e26f57e3f37bbe35725e92ec9cbe2cff65e56266b826d4f2899955b58e9bb456d98
7
+ data.tar.gz: 5601d27d90579ffcc96e686ced3cf665b3b73812821dd847da7f7b188ad509b0f145be929f2f90d598da10464d877795aa1a58f7d6c59b590a58e628b688702f
data/Manifest.txt CHANGED
@@ -4,7 +4,6 @@ README.md
4
4
  Rakefile
5
5
  lib/sportdb/formats.rb
6
6
  lib/sportdb/formats/datafile.rb
7
- lib/sportdb/formats/date.rb
8
7
  lib/sportdb/formats/outline_reader.rb
9
8
  lib/sportdb/formats/season_utils.rb
10
9
  lib/sportdb/formats/version.rb
@@ -12,6 +11,5 @@ test/helper.rb
12
11
  test/test_csv_reader.rb
13
12
  test/test_datafile.rb
14
13
  test/test_datafile_match.rb
15
- test/test_date.rb
16
14
  test/test_outline_reader.rb
17
15
  test/test_season_utils.rb
data/Rakefile CHANGED
@@ -21,6 +21,7 @@ Hoe.spec 'sportdb-formats' do
21
21
 
22
22
  self.extra_deps = [
23
23
  ['alphabets', '>= 0.1.0'],
24
+ ['date-formats', '>= 0.1.0'],
24
25
  ['csvreader', '>= 1.2.4'],
25
26
  ['sportdb-langs', '>= 0.0.1'],
26
27
  ]
@@ -6,7 +6,7 @@ module Formats
6
6
 
7
7
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
8
8
  MINOR = 1
9
- PATCH = 3
9
+ PATCH = 4
10
10
  VERSION = [MAJOR,MINOR,PATCH].join('.')
11
11
 
12
12
  def self.version
@@ -3,6 +3,15 @@
3
3
 
4
4
  ## 3rd party gems
5
5
  require 'alphabets' # downcase_i18n, unaccent, variants, ...
6
+ require 'date-formats' ## todo/fix: also allow loading w/ date/formats - why? why not!!!!
7
+
8
+ module SportDb
9
+ ## add alias for now for old code; DEPRECATED - remove later!!!!!
10
+ DateFinder = DateFormats::DateFinder
11
+ RsssfDateFinder = DateFormats::RsssfDateFinder
12
+ end # module SportDb
13
+
14
+
6
15
  require 'csvreader'
7
16
 
8
17
  def read_csv( path )
@@ -25,7 +34,6 @@ require 'sportdb/formats/outline_reader'
25
34
  require 'sportdb/formats/datafile'
26
35
  require 'sportdb/formats/season_utils'
27
36
 
28
- require 'sportdb/formats/date'
29
37
 
30
38
  ## let's put test configuration in its own namespace / module
31
39
  module SportDb
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sportdb-formats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-05 00:00:00.000000000 Z
11
+ date: 2019-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: alphabets
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: date-formats
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: csvreader
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -95,7 +109,6 @@ files:
95
109
  - Rakefile
96
110
  - lib/sportdb/formats.rb
97
111
  - lib/sportdb/formats/datafile.rb
98
- - lib/sportdb/formats/date.rb
99
112
  - lib/sportdb/formats/outline_reader.rb
100
113
  - lib/sportdb/formats/season_utils.rb
101
114
  - lib/sportdb/formats/version.rb
@@ -103,7 +116,6 @@ files:
103
116
  - test/test_csv_reader.rb
104
117
  - test/test_datafile.rb
105
118
  - test/test_datafile_match.rb
106
- - test/test_date.rb
107
119
  - test/test_outline_reader.rb
108
120
  - test/test_season_utils.rb
109
121
  homepage: https://github.com/sportdb/sport.db
@@ -1,446 +0,0 @@
1
- # encoding: utf-8
2
-
3
- #### fix: move to textutils for reuse !!!!!!!!!! - why?? why not ??
4
-
5
-
6
- module SportDb
7
-
8
-
9
- class DateFinderBase
10
-
11
- MONTH_EN_TO_MM = {
12
- 'Jan' => '1', 'January' => '1',
13
- 'Feb' => '2', 'February' => '2',
14
- 'Mar' => '3', 'March' => '3',
15
- 'Apr' => '4', 'April' => '4',
16
- 'May' => '5',
17
- 'Jun' => '6', 'June' => '6',
18
- 'Jul' => '7', 'July' => '7',
19
- 'Aug' => '8', 'August' => '8',
20
- 'Sep' => '9', 'Sept' => '9', 'September' => '9',
21
- 'Oct' => '10', 'October' => '10',
22
- 'Nov' => '11', 'November' => '11',
23
- 'Dec' => '12', 'December' =>'12' }
24
-
25
- MONTH_FR_TO_MM = {
26
- 'Janvier' => '1', 'Janv' => '1', 'Jan' => '1', ## check janv in use??
27
- 'Février' => '2', 'Févr' => '2', 'Fév' => '2', ## check fevr in use???
28
- 'Mars' => '3', 'Mar' => '3',
29
- 'Avril' => '4', 'Avri' => '4', 'Avr' => '4', ## check avri in use??? if not remove
30
- 'Mai' => '5',
31
- 'Juin' => '6',
32
- 'Juillet' => '7', 'Juil' => '7',
33
- 'Août' => '8',
34
- 'Septembre' => '9', 'Sept' => '9',
35
- 'Octobre' => '10', 'Octo' => '10', 'Oct' => '10', ### check octo in use??
36
- 'Novembre' => '11', 'Nove' => '11', 'Nov' => '11', ## check nove in use??
37
- 'Décembre' => '12', 'Déce' => '12', 'Déc' => '12' } ## check dece in use??
38
-
39
- MONTH_ES_TO_MM = {
40
- 'Ene' => '1', 'Enero' => '1',
41
- 'Feb' => '2',
42
- 'Mar' => '3', 'Marzo' => '3',
43
- 'Abr' => '4', 'Abril' => '4',
44
- 'May' => '5', 'Mayo' => '5',
45
- 'Jun' => '6', 'Junio' => '6',
46
- 'Jul' => '7', 'Julio' => '7',
47
- 'Ago' => '8', 'Agosto' => '8',
48
- 'Sep' => '9', 'Set' => '9', 'Sept' => '9',
49
- 'Oct' => '10',
50
- 'Nov' => '11',
51
- 'Dic' => '12' }
52
-
53
- private
54
- def calc_year( month, day, start_at: ) ## note: start_at required param for now on!!!
55
-
56
- logger.debug " [calc_year] ????-#{month}-#{day} -- start_at: #{start_at}"
57
-
58
- if month >= start_at.month
59
- # assume same year as start_at event (e.g. 2013 for 2013/14 season)
60
- start_at.year
61
- else
62
- # assume year+1 as start_at event (e.g. 2014 for 2013/14 season)
63
- start_at.year+1
64
- end
65
- end
66
-
67
-
68
- def parse_date_time( match_data, opts={} )
69
-
70
- # convert regex match_data captures to hash
71
- # - note: cannont use match_data like a hash (e.g. raises exception if key/name not present/found)
72
- h = {}
73
- # - note: do NOT forget to turn name into symbol for lookup in new hash (name.to_sym)
74
- match_data.names.each { |name| h[name.to_sym] = match_data[name] } # or use match_data.names.zip( match_data.captures ) - more cryptic but "elegant"??
75
-
76
- ## puts "[parse_date_time] match_data:"
77
- ## pp h
78
- logger.debug " [parse_date_time] hash: >#{h.inspect}<"
79
-
80
- h[ :month ] = MONTH_EN_TO_MM[ h[:month_en] ] if h[:month_en]
81
- h[ :month ] = MONTH_ES_TO_MM[ h[:month_es] ] if h[:month_es]
82
- h[ :month ] = MONTH_FR_TO_MM[ h[:month_fr] ] if h[:month_fr]
83
-
84
- month = h[:month]
85
- day = h[:day]
86
- year = h[:year] || calc_year( month.to_i, day.to_i, opts ).to_s
87
-
88
- hours = h[:hours] || '12' # default to 12:00 for HH:MM (hours:minutes)
89
- minutes = h[:minutes] || '00'
90
-
91
- value = '%d-%02d-%02d %02d:%02d' % [year.to_i, month.to_i, day.to_i, hours.to_i, minutes.to_i]
92
- logger.debug " date: >#{value}<"
93
-
94
- DateTime.strptime( value, '%Y-%m-%d %H:%M' )
95
- end
96
-
97
- end # class DateFinderBase
98
-
99
-
100
- class DateFinder < DateFinderBase
101
-
102
- include LogUtils::Logging
103
-
104
- # todo: make more generic for reuse
105
- ### fix:
106
- ### move to textutils
107
- ## date/fr.yml en.yml etc. ???
108
- ## why? why not?
109
-
110
- MONTH_FR = 'Janvier|Janv|Jan|' +
111
- 'Février|Févr|Fév|' +
112
- 'Mars|Mar|' +
113
- 'Avril|Avri|Avr|' +
114
- 'Mai|' +
115
- 'Juin|' +
116
- 'Juillet|Juil|' +
117
- 'Août|' +
118
- 'Septembre|Sept|' +
119
- 'Octobre|Octo|Oct|' +
120
- 'Novembre|Nove|Nov|' +
121
- 'Décembre|Déce|Déc'
122
-
123
- WEEKDAY_FR = 'Lundi|Lun|L|' +
124
- 'Mardi|Mar|Ma|' +
125
- 'Mercredi|Mer|Me|' +
126
- 'Jeudi|Jeu|J|' +
127
- 'Vendredi|Ven|V|' +
128
- 'Samedi|Sam|S|' +
129
- 'Dimanche|Dim|D|'
130
-
131
-
132
- MONTH_EN = 'January|Jan|'+
133
- 'February|Feb|'+
134
- 'March|Mar|'+
135
- 'April|Apr|'+
136
- 'May|'+
137
- 'June|Jun|'+
138
- 'July|Jul|'+
139
- 'August|Aug|'+
140
- 'September|Sept|Sep|'+
141
- 'October|Oct|'+
142
- 'November|Nov|'+
143
- 'December|Dec'
144
-
145
- ###
146
- ## todo: add days
147
- ## 1. Sunday - Sun. 2. Monday - Mon.
148
- ## 3. Tuesday - Tu., Tue., or Tues. 4. Wednesday - Wed.
149
- ## 5. Thursday - Th., Thu., Thur., or Thurs. 6. Friday - Fri.
150
- ## 7. Saturday - Sat.
151
-
152
-
153
- MONTH_ES = 'Enero|Ene|'+
154
- 'Feb|'+
155
- 'Marzo|Mar|'+
156
- 'Abril|Abr|'+
157
- 'Mayo|May|'+
158
- 'Junio|Jun|'+
159
- 'Julio|Jul|'+
160
- 'Agosto|Ago|'+
161
- 'Sept|Set|Sep|'+
162
- 'Oct|'+
163
- 'Nov|'+
164
- 'Dic'
165
-
166
- # todo/fix - add de and es too!!
167
- # note: in Austria - Jänner - in Deutschland Januar allow both ??
168
- # MONTH_DE = 'J[aä]n|Feb|Mär|Apr|Mai|Jun|Jul|Aug|Sep|Okt|Nov|Dez'
169
-
170
-
171
- # e.g. 2012-09-14 20:30 => YYYY-MM-DD HH:MM
172
- # nb: allow 2012-9-3 7:30 e.g. no leading zero required
173
- # regex_db
174
- DB__DATE_TIME_REGEX = /\b
175
- (?<year>\d{4})
176
- -
177
- (?<month>\d{1,2})
178
- -
179
- (?<day>\d{1,2})
180
- \s+
181
- (?<hours>\d{1,2})
182
- :
183
- (?<minutes>\d{2})
184
- \b/x
185
-
186
- # e.g. 2012-09-14 w/ implied hours (set to 12:00)
187
- # nb: allow 2012-9-3 e.g. no leading zero required
188
- # regex_db2
189
- DB__DATE_REGEX = /\b
190
- (?<year>\d{4})
191
- -
192
- (?<month>\d{1,2})
193
- -
194
- (?<day>\d{1,2})
195
- \b/x
196
-
197
- # e.g. 14.09.2012 20:30 => DD.MM.YYYY HH:MM
198
- # nb: allow 2.3.2012 e.g. no leading zero required
199
- # nb: allow hour as 20.30
200
- # regex_de
201
- DD_MM_YYYY__DATE_TIME_REGEX = /\b
202
- (?<day>\d{1,2})
203
- \.
204
- (?<month>\d{1,2})
205
- \.
206
- (?<year>\d{4})
207
- \s+
208
- (?<hours>\d{1,2})
209
- [:.]
210
- (?<minutes>\d{2})
211
- \b/x
212
-
213
- # e.g. 14.09. 20:30 => DD.MM. HH:MM
214
- # nb: allow 2.3.2012 e.g. no leading zero required
215
- # nb: allow hour as 20.30 or 3.30 instead of 03.30
216
- # regex_de2
217
- DD_MM__DATE_TIME_REGEX = /\b
218
- (?<day>\d{1,2})
219
- \.
220
- (?<month>\d{1,2})
221
- \.
222
- \s+
223
- (?<hours>\d{1,2})
224
- [:.]
225
- (?<minutes>\d{2})
226
- \b/x
227
-
228
- # e.g. 14.09.2012 => DD.MM.YYYY w/ implied hours (set to 12:00)
229
- # regex_de3
230
- DD_MM_YYYY__DATE_REGEX = /\b
231
- (?<day>\d{1,2})
232
- \.
233
- (?<month>\d{1,2})
234
- \.
235
- (?<year>\d{4})
236
- \b/x
237
-
238
- # e.g. 14.09. => DD.MM. w/ implied year and implied hours (set to 12:00)
239
- # note: allow end delimiter ] e.g. [Sa 12.01.] or end-of-string ($) too
240
- # note: we use a lookahead for last part e.g. (?:\s+|$|[\]]) - do NOT cosume
241
- # regex_de4 (use lookahead assert)
242
- DD_MM__DATE_REGEX = /\b
243
- (?<day>\d{1,2})
244
- \.
245
- (?<month>\d{1,2})
246
- \.
247
- (?=\s+|$|[\]])/x ## note: allow end-of-string/line too
248
-
249
-
250
- # e.g. 12 May 2013 14:00 => D|DD.MMM.YYYY H|HH:MM
251
- EN__DD_MONTH_YYYY__DATE_TIME_REGEX = /\b
252
- (?<day>\d{1,2})
253
- \s
254
- (?<month_en>#{MONTH_EN})
255
- \s
256
- (?<year>\d{4})
257
- \s+
258
- (?<hours>\d{1,2})
259
- :
260
- (?<minutes>\d{2})
261
- \b/x
262
-
263
- ###
264
- # fix: pass in lang (e.g. en or es)
265
- # only process format for lang plus fallback to en?
266
- # e.g. EN__DD_MONTH and ES__DD_MONTH depend on order for match (first listed will match)
267
-
268
- # e.g. 12 May => D|DD.MMM w/ implied year and implied hours
269
- EN__DD_MONTH__DATE_REGEX = /\b
270
- (?<day>\d{1,2})
271
- \s
272
- (?<month_en>#{MONTH_EN})
273
- \b/x
274
-
275
-
276
- # e.g. Jun/12 2011 14:00
277
- EN__MONTH_DD_YYYY__DATE_TIME_REGEX = /\b
278
- (?<month_en>#{MONTH_EN})
279
- \/
280
- (?<day>\d{1,2})
281
- \s
282
- (?<year>\d{4})
283
- \s+
284
- (?<hours>\d{1,2})
285
- :
286
- (?<minutes>\d{2})
287
- \b/x
288
-
289
- # e.g. Jun/12 14:00 w/ implied year H|HH:MM
290
- EN__MONTH_DD__DATE_TIME_REGEX = /\b
291
- (?<month_en>#{MONTH_EN})
292
- \/
293
- (?<day>\d{1,2})
294
- \s+
295
- (?<hours>\d{1,2})
296
- :
297
- (?<minutes>\d{2})
298
- \b/x
299
-
300
- # e.g. Jun/12 2013 w/ implied hours (set to 12:00)
301
- EN__MONTH_DD_YYYY__DATE_REGEX = /\b
302
- (?<month_en>#{MONTH_EN})
303
- \/
304
- (?<day>\d{1,2})
305
- \s
306
- (?<year>\d{4})
307
- \b/x
308
-
309
- # e.g. Jun/12 w/ implied year and implied hours (set to 12:00)
310
- # note: allow space too e.g Jun 12 -- check if conflicts w/ other formats??? (added for rsssf reader)
311
- # -- fix: might eat french weekday mar 12 is mardi (mar) !!! see FR__ pattern
312
- # fix: remove space again for now - and use simple en date reader or something!!!
313
- ## was [\/ ] changed back to \/
314
- EN__MONTH_DD__DATE_REGEX = /\b
315
- (?<month_en>#{MONTH_EN})
316
- \/
317
- (?<day>\d{1,2})
318
- \b/x
319
-
320
-
321
- # e.g. 12 Ene w/ implied year and implied hours (set to 12:00)
322
- ES__DD_MONTH__DATE_REGEX = /\b
323
- (?<day>\d{1,2})
324
- \s
325
- (?<month_es>#{MONTH_ES})
326
- \b/x
327
-
328
- # e.g. Ven 8 Août or [Ven 8 Août] or Ven 8. Août or [Ven 8. Août]
329
- ### note: do NOT consume [] in regex (use lookahead assert)
330
- FR__WEEKDAY_DD_MONTH__DATE_REGEX = /\b
331
- (?:#{WEEKDAY_FR}) # note: skip weekday for now; do NOT capture
332
- \s+
333
- (?<day>\d{1,2})
334
- \.? # note: make dot optional
335
- \s+
336
- (?<month_fr>#{MONTH_FR})
337
- (?=\s+|$|[\]])/x ## note: allow end-of-string/line too
338
-
339
-
340
-
341
-
342
- # map table - 1) tag, 2) regex - note: order matters; first come-first matched/served
343
- FORMATS = [
344
- [ '[YYYY_MM_DD_hh_mm]', DB__DATE_TIME_REGEX ],
345
- [ '[YYYY_MM_DD]', DB__DATE_REGEX ],
346
- [ '[DD_MM_YYYY_hh_mm]', DD_MM_YYYY__DATE_TIME_REGEX ],
347
- [ '[DD_MM_hh_mm]', DD_MM__DATE_TIME_REGEX ],
348
- [ '[DD_MM_YYYY]', DD_MM_YYYY__DATE_REGEX ],
349
- [ '[DD_MM]', DD_MM__DATE_REGEX ],
350
- [ '[FR_WEEKDAY_DD_MONTH]', FR__WEEKDAY_DD_MONTH__DATE_REGEX ],
351
- [ '[EN_DD_MONTH_YYYY_hh_mm]', EN__DD_MONTH_YYYY__DATE_TIME_REGEX ],
352
- [ '[EN_MONTH_DD_YYYY_hh_mm]', EN__MONTH_DD_YYYY__DATE_TIME_REGEX ],
353
- [ '[EN_MONTH_DD_hh_mm]', EN__MONTH_DD__DATE_TIME_REGEX ],
354
- [ '[EN_MONTH_DD_YYYY]', EN__MONTH_DD_YYYY__DATE_REGEX ],
355
- [ '[EN_MONTH_DD]', EN__MONTH_DD__DATE_REGEX ],
356
- [ '[EN_DD_MONTH]', EN__DD_MONTH__DATE_REGEX ],
357
- [ '[ES_DD_MONTH]', ES__DD_MONTH__DATE_REGEX ]
358
- ]
359
-
360
-
361
-
362
- def initialize
363
- # nothing here for now
364
- end
365
-
366
- def find!( line, opts={} )
367
- # fix: use more lookahead for all required trailing spaces!!!!!
368
- # fix: use <name capturing group> for month,day,year etc.!!!
369
-
370
- #
371
- # fix: !!!!
372
- # date in [] will become [[DATE.DE4]] - when getting removed will keep ]!!!!
373
- # fix: change regex to \[[A-Z0-9.]\] !!!!!! plus add unit test too!!!
374
- #
375
-
376
- md = nil
377
- FORMATS.each do |format|
378
- tag = format[0]
379
- pattern = format[1]
380
- md=pattern.match( line )
381
- if md
382
- date = parse_date_time( md, opts )
383
- ## fix: use md[0] e.g. match for sub! instead of using regex again - why? why not???
384
- ## fix: use md.begin(0), md.end(0)
385
- line.sub!( md[0], tag )
386
- ## todo/fix: make sure match data will not get changed (e.g. using sub! before parse_date_time)
387
- return date
388
- end
389
- # no match; continue; try next pattern
390
- end
391
-
392
- return nil # no match found
393
- end
394
-
395
- end # class DateFinder
396
-
397
-
398
- class RsssfDateFinder < DateFinderBase
399
-
400
- include LogUtils::Logging
401
-
402
- MONTH_EN = 'Jan|'+
403
- 'Feb|'+
404
- 'March|Mar|'+
405
- 'April|Apr|'+
406
- 'May|'+
407
- 'June|Jun|'+
408
- 'July|Jul|'+
409
- 'Aug|'+
410
- 'Sept|Sep|'+
411
- 'Oct|'+
412
- 'Nov|'+
413
- 'Dec'
414
-
415
- ## e.g.
416
- ## [Jun 7] or [Aug 12] etc. - not MUST include brackets e.g. []
417
- ##
418
- ## check add \b at the beginning and end - why?? why not?? working??
419
- EN__MONTH_DD__DATE_REGEX = /\[
420
- (?<month_en>#{MONTH_EN})
421
- \s
422
- (?<day>\d{1,2})
423
- \]/x
424
-
425
- def find!( line, opts={} )
426
- # fix: use more lookahead for all required trailing spaces!!!!!
427
- # fix: use <name capturing group> for month,day,year etc.!!!
428
-
429
- tag = '[EN_MONTH_DD]'
430
- pattern = EN__MONTH_DD__DATE_REGEX
431
- md = pattern.match( line )
432
- if md
433
- date = parse_date_time( md, opts )
434
- ## fix: use md[0] e.g. match for sub! instead of using regex again - why? why not???
435
- ## fix: use md.begin(0), md.end(0)
436
- line.sub!( md[0], tag )
437
- ## todo/fix: make sure match data will not get changed (e.g. using sub! before parse_date_time)
438
- return date
439
- end
440
- return nil # no match found
441
- end
442
-
443
-
444
- end ## class RsssfDateFinder
445
-
446
- end # module SportDb
data/test/test_date.rb DELETED
@@ -1,100 +0,0 @@
1
- # encoding: utf-8
2
-
3
- ###
4
- # to run use
5
- # ruby -I ./lib -I ./test test/test_date.rb
6
-
7
- require 'helper'
8
-
9
- class TestDate < MiniTest::Test
10
-
11
- def test_date
12
- data = [
13
- [ '19.01.2013 22.00', '2013-01-19 22:00' ],
14
- [ '21.01.2013 21.30', '2013-01-21 21:30' ],
15
- [ '26.01.2013', '2013-01-26' ],
16
- [ '[26.01.2013]', '2013-01-26' ],
17
- [ '[21.1.]', '2013-01-21 12:00' ]
18
- ]
19
-
20
- assert_dates( data, start_at: Date.new( 2013, 1, 1 ) )
21
- end
22
-
23
- def test_date_fr
24
- data = [
25
- [ '[Ven 08. Août]', '2014-08-08' ],
26
- [ 'Ven 08. Août', '2014-08-08' ],
27
- [ 'Ven 8. Août', '2014-08-08' ],
28
- [ '[Sam 9. Août]', '2014-08-09' ],
29
- [ '[Dim 10. Août]', '2014-08-10' ],
30
- [ '[Sam 31. Janv]', '2015-01-31' ],
31
- [ '[Sam 7. Févr]', '2015-02-07' ],
32
- [ '[Sam 31. Jan]', '2015-01-31' ],
33
- [ '[Sam 7. Fév]', '2015-02-07' ],
34
- ]
35
-
36
- assert_dates( data, start_at: Date.new( 2014, 8, 1 ) )
37
- end
38
-
39
- def test_date_en
40
- data = [
41
- [ 'Jun/12 2011 14:00', '2011-06-12 14:00' ],
42
- [ 'Oct/12 2013 16:00', '2013-10-12 16:00' ],
43
-
44
- [ 'Jan/26 2011', '2011-01-26' ],
45
- [ 'Jan/26 2011', '2011-01-26 12:00' ],
46
-
47
- [ 'Jan/26', '2013-01-26' ],
48
- [ 'Jan/26', '2013-01-26 12:00' ],
49
- [ '26 January', '2013-01-26' ],
50
- [ '26 January', '2013-01-26 12:00' ],
51
-
52
- [ 'Jun/13', '2013-06-13' ],
53
- [ 'Jun/13', '2013-06-13 12:00' ],
54
- [ '13 June', '2013-06-13' ],
55
- [ '13 June', '2013-06-13 12:00' ]
56
- ]
57
-
58
- assert_dates( data, start_at: Date.new( 2013, 1, 1 ) )
59
- end
60
-
61
-
62
- private
63
-
64
- def assert_dates( data, opts )
65
- data.each do |rec|
66
- line = rec[0]
67
- str = rec[1]
68
- if str.index( ':' )
69
- assert_datetime( DateTime.strptime( str, '%Y-%m-%d %H:%M' ), parse_date( line, opts ))
70
- else
71
- assert_date( DateTime.strptime( str, '%Y-%m-%d' ), parse_date( line, opts ))
72
- end
73
- end
74
- end
75
-
76
- ## todo: check if assert_datetime or assert_date exist already? what is the best practice to check dates ???
77
- def assert_date( exp, act )
78
- assert_equal exp.year, act.year
79
- assert_equal exp.month, act.month
80
- assert_equal exp.day, act.day
81
- end
82
-
83
- def assert_time( exp, act )
84
- assert_equal exp.hour, act.hour
85
- assert_equal exp.min, act.min
86
- end
87
-
88
- def assert_datetime( exp, act )
89
- assert_date( exp, act )
90
- assert_time( exp, act )
91
- end
92
-
93
-
94
- def parse_date( line, opts={} )
95
- # e.g. lets you pass in opts[:start_at] ???
96
- finder = SportDb::DateFinder.new
97
- finder.find!( line, opts )
98
- end
99
-
100
- end # class TestDate