sportdb-formats 0.1.1 → 0.1.2

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.
@@ -1,9 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'pp'
4
- require 'date'
5
- require 'fileutils'
6
-
7
3
 
8
4
  ## 3rd party gems
9
5
  require 'alphabets' # downcase_i18n, unaccent, variants, ...
@@ -18,6 +14,9 @@ def parse_csv( txt )
18
14
  end
19
15
 
20
16
 
17
+ require 'textutils' # TextUtils::Classifier, ...
18
+
19
+
21
20
  ###
22
21
  # our own code
23
22
  require 'sportdb/formats/version' # let version always go first
@@ -25,7 +24,8 @@ require 'sportdb/formats/outline_reader'
25
24
  require 'sportdb/formats/datafile'
26
25
  require 'sportdb/formats/season_utils'
27
26
 
28
-
27
+ require 'sportdb/formats/lang'
28
+ require 'sportdb/formats/date'
29
29
 
30
30
  ## let's put test configuration in its own namespace / module
31
31
  module SportDb
@@ -40,5 +40,17 @@ end
40
40
  end # module SportDb
41
41
 
42
42
 
43
+ module SportDb
44
+ def self.lang
45
+ # todo/fix: find a better way for single instance ??
46
+ # will get us ruby warning: instance variable @lang not initialized => find a better way!!!
47
+ # just use @lang w/o .nil? e.g.
48
+ # @lang =|| Lang.new why? why not?? or better use @@lang =|| Lang.new for class variable!!!
49
+ @lang ||= Lang.new
50
+ @lang
51
+ end
52
+ end # module SportDb
53
+
54
+
43
55
 
44
56
  puts SportDb::Formats.banner # say hello
@@ -9,10 +9,10 @@ require 'helper'
9
9
 
10
10
  class TestDatafileMatch < MiniTest::Test
11
11
 
12
- def match_clubs( txt ) Datafile::CLUBS_REGEX.match( txt ); end
13
- def match_clubs_wiki( txt ) Datafile::CLUBS_WIKI_REGEX.match( txt ); end
14
- def match_leagues( txt ) Datafile::LEAGUES_REGEX.match( txt ); end
15
- def match_conf( txt ) Datafile::CONF_REGEX.match( txt ); end
12
+ def match_clubs( txt ) Datafile.match_clubs( txt ); end
13
+ def match_clubs_wiki( txt ) Datafile.match_clubs_wiki( txt ); end
14
+ def match_leagues( txt ) Datafile.match_leagues( txt ); end
15
+ def match_conf( txt ) Datafile.match_conf( txt ); end
16
16
 
17
17
 
18
18
  CLUBS_TXT = [ ## with country code
data/test/test_date.rb ADDED
@@ -0,0 +1,100 @@
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
data/test/test_lang.rb ADDED
@@ -0,0 +1,130 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_lang.rb
6
+ # or better
7
+ # rake -I ./lib test
8
+
9
+ require 'helper'
10
+
11
+ class TestLang < MiniTest::Test
12
+
13
+ def test_getters
14
+
15
+ lang = SportDb.lang
16
+ lang.lang = 'en'
17
+
18
+ group = 'Group'
19
+
20
+ round = 'Round|Matchday|Week'
21
+ round << '|Round of 32|Last 32'
22
+ round << '|Round of 16|Last 16|8th finals'
23
+ round << '|Quarterfinals|Quarter-finals|Quarters|Quarterfinal|Last 8'
24
+ round << '|Semifinals|Semi-finals|Semis|Last 4'
25
+ round << '|Fifth place match|Fifth place|5th place match|5th place final|5th place|Match for fifth place|Match for 5th place'
26
+ round << '|Third place match|Third-place match|Third place|3rd place match|3rd place final|3rd place|Match for third place|Match for 3rd place|Third-place play-off|Third place play-off'
27
+ round << '|Final|Finals'
28
+ round << '|Playoff|Playoffs|Play-off|Play-offs|Play-off for quarter-finals'
29
+
30
+ knockout_round = 'Round of 32|Last 32'
31
+ knockout_round << '|Round of 16|Last 16|8th finals'
32
+ knockout_round << '|Quarterfinals|Quarter-finals|Quarters|Quarterfinal|Last 8'
33
+ knockout_round << '|Semifinals|Semi-finals|Semis|Last 4'
34
+ knockout_round << '|Fifth place match|Fifth place|5th place match|5th place final|5th place|Match for fifth place|Match for 5th place'
35
+ knockout_round << '|Third place match|Third-place match|Third place|3rd place match|3rd place final|3rd place|Match for third place|Match for 3rd place|Third-place play-off|Third place play-off'
36
+ knockout_round << '|Final|Finals'
37
+ knockout_round << '|Playoff|Playoffs|Play-off|Play-offs|Play-off for quarter-finals'
38
+
39
+ assert_equal group, lang.group
40
+ assert_equal round, lang.round
41
+ assert_equal knockout_round, lang.knockout_round
42
+
43
+ # NB: call twice to test caching with ||=
44
+ assert_equal group, lang.group
45
+ assert_equal round, lang.round
46
+ assert_equal knockout_round, lang.knockout_round
47
+
48
+ end
49
+
50
+ def test_getters_de
51
+ lang = SportDb.lang
52
+ lang.lang = 'de'
53
+
54
+ group = 'Gruppe'
55
+
56
+ round = 'Spieltag|Runde'
57
+ round << '|Sechzehntelfinale|1/16 Finale'
58
+ round << '|Achtelfinale|1/8 Finale'
59
+ round << '|Viertelfinale|1/4 Finale'
60
+ round << '|Halbfinale|Semifinale|1/2 Finale'
61
+ round << '|Spiel um Platz 5'
62
+ round << '|Spiel um Platz 3'
63
+ round << '|Finale|Endspiel'
64
+
65
+ knockout_round = 'Sechzehntelfinale|1/16 Finale'
66
+ knockout_round << '|Achtelfinale|1/8 Finale'
67
+ knockout_round << '|Viertelfinale|1/4 Finale'
68
+ knockout_round << '|Halbfinale|Semifinale|1/2 Finale'
69
+ knockout_round << '|Spiel um Platz 5'
70
+ knockout_round << '|Spiel um Platz 3'
71
+ knockout_round << '|Finale|Endspiel'
72
+
73
+
74
+ assert_equal group, lang.group
75
+ assert_equal round, lang.round
76
+ assert_equal knockout_round, lang.knockout_round
77
+
78
+ # NB: call twice to test caching with ||=
79
+
80
+ assert_equal group, lang.group
81
+ assert_equal round, lang.round
82
+ assert_equal knockout_round, lang.knockout_round
83
+ end
84
+
85
+ def test_regex_knockout_round
86
+ lang = SportDb.lang
87
+ lang.lang = 'en'
88
+
89
+ lines = [
90
+ '(4) Quarter-finals',
91
+ '(5) Semi-finals',
92
+ '(6) Final',
93
+ '(1) Play-off 1st Leg // 11–15 October',
94
+ '(2) Play-off 2nd Leg // 15-19 November',
95
+ '(1) Play-off for quarter-finals',
96
+ '(4) Match for fifth place',
97
+ '(5) Match for third place',
98
+ ## check for ALL UPCASE too
99
+ '(4) QUARTER-FINALS',
100
+ '(5) SEMI-FINALS',
101
+ '(6) FINAL'
102
+ ]
103
+
104
+ lines.each do |line|
105
+ assert( line =~ lang.regex_knockout_round )
106
+ end
107
+
108
+ end
109
+
110
+ def test_regex_knockout_round_de
111
+ lang = SportDb.lang
112
+ lang.lang = 'de'
113
+
114
+ lines = [
115
+ '(1) Achtelfinale // Di+Mi 14.+15. & 21.+22. Feb 2012',
116
+ '(2) Achtelfinale Rückspiele // Di+Mi 6.+7. & 13.+14. März 2012',
117
+ '(3) Viertelfinale // Di+Mi 27.+28. März 2012',
118
+ '(4) Viertelfinale Rückspiele // Di+Mi 3.+4. April 2012',
119
+ '(5) Halbfinale // Di+Mi 17.+18. April 2012',
120
+ '(6) Halbfinale Rückspiele // Di+Mi 24.+25. April 2012',
121
+ '(7) Finale // Sa 19. Mai 2012'
122
+ ]
123
+
124
+ lines.each do |line|
125
+ assert( line =~ lang.regex_knockout_round )
126
+ end
127
+
128
+ end
129
+
130
+ end # class TestLang
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.1
4
+ version: 0.1.2
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-10-29 00:00:00.000000000 Z
11
+ date: 2019-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: alphabets
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.2.4
41
+ - !ruby/object:Gem::Dependency
42
+ name: textutils
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 1.4.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 1.4.0
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rdoc
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -79,8 +93,17 @@ files:
79
93
  - Manifest.txt
80
94
  - README.md
81
95
  - Rakefile
96
+ - config/fixtures/de.yml
97
+ - config/fixtures/en.yml
98
+ - config/fixtures/es.yml
99
+ - config/fixtures/fr.yml
100
+ - config/fixtures/it.yml
101
+ - config/fixtures/pt.yml
102
+ - config/fixtures/ro.yml
82
103
  - lib/sportdb/formats.rb
83
104
  - lib/sportdb/formats/datafile.rb
105
+ - lib/sportdb/formats/date.rb
106
+ - lib/sportdb/formats/lang.rb
84
107
  - lib/sportdb/formats/outline_reader.rb
85
108
  - lib/sportdb/formats/season_utils.rb
86
109
  - lib/sportdb/formats/version.rb
@@ -88,6 +111,8 @@ files:
88
111
  - test/test_csv_reader.rb
89
112
  - test/test_datafile.rb
90
113
  - test/test_datafile_match.rb
114
+ - test/test_date.rb
115
+ - test/test_lang.rb
91
116
  - test/test_outline_reader.rb
92
117
  - test/test_season_utils.rb
93
118
  homepage: https://github.com/sportdb/sport.db