sportdb-structs 0.1.1 → 0.1.3

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
- SHA1:
3
- metadata.gz: 0da18097a3c12d49e15eeb7963a4b62a030f4672
4
- data.tar.gz: 75510bd91eb242f0617671bd115cced1e8e52c3c
2
+ SHA256:
3
+ metadata.gz: 9569b6727737da1a3c241e4acae88a19ea61e7cc132e752b1d391628424db916
4
+ data.tar.gz: 37ad5ee8f954dfdb3221060b500eed898461ce957ed257d2dd58e6b6467bae7c
5
5
  SHA512:
6
- metadata.gz: 8664d51d3ac92e5e1b214d459594806d83af703c8ee601ca37958ac23cbe1822b81396d03bca2f8c304f31cc3891e732dd7d2fc364ecf3218cee15a4565d51b4
7
- data.tar.gz: 789287b40ef9f4c8359a3a241836ea2747a53a4406b70e652ca083aca766b96b481bcf2281a79ce88bb81887428139e27e33caa65e7bf741d5c18de78e767158
6
+ metadata.gz: 4eb9e97280e9a390f188409fd8dab427b96dcc9e0ed9d81de20546254dc02903b9d7c28ab22efbaea0fb7f13cf9ea685c81ab1f88fc67cd69f9d8b017579d3ab
7
+ data.tar.gz: 4bcb33bdc129b67439817eea7204bd42aaf26a20b0b1962a046eb182d8d48746b38452aa5a177a01c7f522e3bcab203053778d42e75212bde5128405eeb37bf0
data/Manifest.txt CHANGED
@@ -8,7 +8,6 @@ lib/sportdb/structs/goal_parser_csv.rb
8
8
  lib/sportdb/structs/match_parser_csv.rb
9
9
  lib/sportdb/structs/match_status_parser.rb
10
10
  lib/sportdb/structs/name_helper.rb
11
- lib/sportdb/structs/season.rb
12
11
  lib/sportdb/structs/structs/country.rb
13
12
  lib/sportdb/structs/structs/goal.rb
14
13
  lib/sportdb/structs/structs/group.rb
@@ -26,4 +25,3 @@ test/test_csv_reader.rb
26
25
  test/test_match.rb
27
26
  test/test_match_status_parser.rb
28
27
  test/test_name_helper.rb
29
- test/test_season.rb
data/Rakefile CHANGED
@@ -11,7 +11,7 @@ Hoe.spec 'sportdb-structs' do
11
11
  self.urls = { home: 'https://github.com/sportdb/sport.db' }
12
12
 
13
13
  self.author = 'Gerald Bauer'
14
- self.email = 'opensport@googlegroups.com'
14
+ self.email = 'opensport@googlegroups.com'
15
15
 
16
16
  # switch extension to .markdown for gihub formatting
17
17
  self.readme_file = 'README.md'
@@ -23,6 +23,7 @@ Hoe.spec 'sportdb-structs' do
23
23
  ['alphabets', '>= 1.0.0'],
24
24
  ['date-formats', '>= 1.0.2'],
25
25
  ['score-formats', '>= 0.1.1'],
26
+ ['season-formats', '>= 0.0.1'],
26
27
  ['csvreader', '>= 1.2.4'],
27
28
  ['sportdb-langs', '>= 0.1.1'],
28
29
  ]
@@ -34,7 +34,7 @@ class Match
34
34
  @score1agg = @score2agg = nil ## full time (all legs) aggregated
35
35
 
36
36
 
37
- update( kwargs ) unless kwargs.empty?
37
+ update( **kwargs ) unless kwargs.empty?
38
38
  end
39
39
 
40
40
  def update( **kwargs )
@@ -50,7 +50,7 @@ class Team
50
50
  @alt_names = []
51
51
  @alt_names_auto = []
52
52
 
53
- update( kwargs ) unless kwargs.empty?
53
+ update( **kwargs ) unless kwargs.empty?
54
54
  end
55
55
 
56
56
  def update( **kwargs )
@@ -4,7 +4,7 @@ module SportDb
4
4
  module Structs
5
5
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
6
6
  MINOR = 1
7
- PATCH = 1
7
+ PATCH = 3
8
8
  VERSION = [MAJOR,MINOR,PATCH].join('.')
9
9
 
10
10
  def self.version
@@ -1,6 +1,7 @@
1
1
  ## 3rd party gems
2
- require 'alphabets' # downcase_i18n, unaccent, variants, ...
3
- require 'date/formats' # DateFormats.parse, find!, ...
2
+ require 'alphabets' # downcase_i18n, unaccent, variants, ...
3
+ require 'date/formats' # DateFormats.parse, find!, ...
4
+ require 'season/formats' # Season.parse, ...
4
5
  require 'score/formats'
5
6
  require 'csvreader'
6
7
 
@@ -58,8 +59,6 @@ require 'sportdb/structs/version' # let version always go first
58
59
  require 'sportdb/structs/config' # let "global" config "framework" go next - why? why not?
59
60
 
60
61
 
61
- require 'sportdb/structs/season'
62
-
63
62
  require 'sportdb/structs/name_helper'
64
63
 
65
64
  require 'sportdb/structs/structs/country'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sportdb-structs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-15 00:00:00.000000000 Z
11
+ date: 2022-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: alphabets
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.1.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: season-formats
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 0.0.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 0.0.1
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: csvreader
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -84,30 +98,36 @@ dependencies:
84
98
  name: rdoc
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
- - - "~>"
101
+ - - ">="
88
102
  - !ruby/object:Gem::Version
89
103
  version: '4.0'
104
+ - - "<"
105
+ - !ruby/object:Gem::Version
106
+ version: '7'
90
107
  type: :development
91
108
  prerelease: false
92
109
  version_requirements: !ruby/object:Gem::Requirement
93
110
  requirements:
94
- - - "~>"
111
+ - - ">="
95
112
  - !ruby/object:Gem::Version
96
113
  version: '4.0'
114
+ - - "<"
115
+ - !ruby/object:Gem::Version
116
+ version: '7'
97
117
  - !ruby/object:Gem::Dependency
98
118
  name: hoe
99
119
  requirement: !ruby/object:Gem::Requirement
100
120
  requirements:
101
121
  - - "~>"
102
122
  - !ruby/object:Gem::Version
103
- version: '3.16'
123
+ version: '3.23'
104
124
  type: :development
105
125
  prerelease: false
106
126
  version_requirements: !ruby/object:Gem::Requirement
107
127
  requirements:
108
128
  - - "~>"
109
129
  - !ruby/object:Gem::Version
110
- version: '3.16'
130
+ version: '3.23'
111
131
  description: sportdb-structs - sport data structures for matches, scores, leagues,
112
132
  seasons, rounds, groups, teams, clubs and more
113
133
  email: opensport@googlegroups.com
@@ -128,7 +148,6 @@ files:
128
148
  - lib/sportdb/structs/match_parser_csv.rb
129
149
  - lib/sportdb/structs/match_status_parser.rb
130
150
  - lib/sportdb/structs/name_helper.rb
131
- - lib/sportdb/structs/season.rb
132
151
  - lib/sportdb/structs/structs/country.rb
133
152
  - lib/sportdb/structs/structs/goal.rb
134
153
  - lib/sportdb/structs/structs/group.rb
@@ -146,12 +165,11 @@ files:
146
165
  - test/test_match.rb
147
166
  - test/test_match_status_parser.rb
148
167
  - test/test_name_helper.rb
149
- - test/test_season.rb
150
168
  homepage: https://github.com/sportdb/sport.db
151
169
  licenses:
152
170
  - Public Domain
153
171
  metadata: {}
154
- post_install_message:
172
+ post_install_message:
155
173
  rdoc_options:
156
174
  - "--main"
157
175
  - README.md
@@ -168,9 +186,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
186
  - !ruby/object:Gem::Version
169
187
  version: '0'
170
188
  requirements: []
171
- rubyforge_project:
172
- rubygems_version: 2.5.2
173
- signing_key:
189
+ rubygems_version: 3.3.7
190
+ signing_key:
174
191
  specification_version: 4
175
192
  summary: sportdb-structs - sport data structures for matches, scores, leagues, seasons,
176
193
  rounds, groups, teams, clubs and more
@@ -1,199 +0,0 @@
1
-
2
- ### note: make Season like Date a "top-level" / "generic" class
3
-
4
-
5
- class Season
6
- ##
7
- ## todo: add (optional) start_date and end_date - why? why not?
8
-
9
- ## todo/todo/todo/check/check/check !!!
10
- ## todo: add a kernel Seaons e.g. Season('2011/12')
11
- ## forward to Season.convert( *args ) - why? why not?
12
-
13
- ## todo: add unicode - too - why? why not? see wikipedia pages, for example
14
-
15
- YYYY_YYYY_RE = %r{^ ## e.g. 2011-2012 or 2011/2012
16
- (\d{4})
17
- [/-]
18
- (\d{4})
19
- $
20
- }x
21
- YYYY_YY_RE = %r{^ ## e.g. 2011-12 or 2011/12
22
- (\d{4})
23
- [/-]
24
- (\d{2})
25
- $
26
- }x
27
- YYYY_Y_RE = %r{^ ## e.g. 2011-2 or 2011/2
28
- (\d{4})
29
- [/-]
30
- (\d{1})
31
- $
32
- }x
33
- YYYY_RE = %r{^ ## e.g. 2011
34
- (\d{4})
35
- $
36
- }x
37
-
38
-
39
- def self.parse( str )
40
- new( *_parse( str ))
41
- end
42
-
43
- def self._parse( str ) ## "internal" parse helper
44
- if str =~ YYYY_YYYY_RE ## e.g. 2011/2012
45
- [$1.to_i, $2.to_i]
46
- elsif str =~ YYYY_YY_RE ## e.g. 2011/12
47
- fst = $1.to_i
48
- snd = $2.to_i
49
- snd_exp = '%02d' % [(fst+1) % 100] ## double check: e.g 00 == 00, 01==01 etc.
50
- raise ArgumentError, "[Season.parse] invalid year in season >>#{str}<<; expected #{snd_exp} but got #{$2}" if snd_exp != $2
51
- [fst, fst+1]
52
- elsif str =~ YYYY_Y_RE ## e.g. 2011/2
53
- fst = $1.to_i
54
- snd = $2.to_i
55
- snd_exp = '%d' % [(fst+1) % 10] ## double check: e.g 0 == 0, 1==1 etc.
56
- raise ArgumentError, "[Season.parse] invalid year in season >>#{str}<<; expected #{snd_exp} but got #{$2}" if snd_exp != $2
57
- [fst, fst+1]
58
- elsif str =~ YYYY_RE ## e.g. 2011
59
- [$1.to_i]
60
- else
61
- raise ArgumentError, "[Season.parse] unkown season format >>#{str}<<; sorry cannot parse"
62
- end
63
- end
64
-
65
-
66
- def self.convert( *args ) ## note: used by Kernel method Season()
67
- if args.size == 1 && args[0].is_a?( Season )
68
- args[0] # pass through / along as is 1:1
69
- elsif args.size == 1 && args[0].is_a?( String )
70
- parse( args[0] )
71
- elsif args.size == 1 && args[0].is_a?( Integer ) && args[0] > 9999
72
- ## note: allow convenience "hack" such as:
73
- # 202021 or 2020_21 => '2020/21' or
74
- # 2020_1 or 2020_1 => '2020/21' or
75
- # 20202021 or 2020_2021 => '2020/21'
76
- str = args[0].to_s
77
- parse( "#{str[0..3]}/#{str[4..-1]}" )
78
- else ## assume all integer args e.g. 2020 or 2020, 2021 and such
79
- new( *args ) ## try conversion with new
80
- end
81
- end
82
-
83
-
84
- attr_reader :start_year,
85
- :end_year
86
-
87
- def initialize( *args ) ## change args to years - why? why not?
88
- if args.size == 1 && args[0].is_a?( Integer )
89
- @start_year = args[0]
90
- @end_year = args[0]
91
- elsif args.size == 2 && args[0].is_a?( Integer ) &&
92
- args[1].is_a?( Integer )
93
- @start_year = args[0]
94
- @end_year = args[1]
95
- end_year_exp = @start_year+1
96
- raise ArgumentError, "[Season] invalid year in season >>#{to_s}<<; expected #{end_year_exp} but got #{@end_year}" if end_year_exp != @end_year
97
- else
98
- pp args
99
- raise ArgumentError, "[Season] expected season start year (integer) with opt. end year"
100
- end
101
- end
102
-
103
-
104
-
105
- ## convenience helper - move to sportdb or such - remove - why - why not???
106
- def start_date ## generate "generic / syntetic start date" - keep helper - why? why not?
107
- if year?
108
- Date.new( start_year, 1, 1 )
109
- else
110
- Date.new( start_year 1, 7 )
111
- end
112
- end
113
-
114
-
115
- ## single-year season e.g. 2011 if start_year is end_year - todo - find a better name?
116
- def year?() @start_year == @end_year; end
117
-
118
- def prev
119
- if year?
120
- Season.new( @start_year-1 )
121
- else
122
- Season.new( @start_year-1, @end_year-1 )
123
- end
124
- end
125
-
126
- def next
127
- if year?
128
- Season.new( @start_year+1 )
129
- else
130
- Season.new( @start_year+1, @end_year+1 )
131
- end
132
- end
133
- alias_method :succ, :next ## add support for ranges
134
-
135
-
136
- include Comparable
137
- def <=>(other)
138
- ## todo/fix/fix: check if other is_a?( Season )!!!
139
- ## what to return if other type/class ??
140
- ## note: check special edge case - year season and other e.g.
141
- ## 2010 <=> 2010/2011
142
-
143
- res = @start_year <=> other.start_year
144
- res = @end_year <=> other.end_year if res == 0
145
- res
146
- end
147
-
148
-
149
- def to_formatted_s( format=:default, sep: '/' )
150
- if year?
151
- '%d' % @start_year
152
- else
153
- case format
154
- when :default, :short, :s ## e.g. 1999/00 or 2019/20
155
- "%d#{sep}%02d" % [@start_year, @end_year % 100]
156
- when :long, :l ## e.g. 1999/2000 or 2019/2020
157
- "%d#{sep}%d" % [@start_year, @end_year]
158
- else
159
- raise ArgumentError, "[Season.to_s] unsupported format >#{format}<"
160
- end
161
- end
162
- end
163
- alias_method :to_s, :to_formatted_s
164
-
165
- def key() to_s( :short ); end
166
- alias_method :to_key, :key
167
- alias_method :name, :key
168
- alias_method :title, :key
169
-
170
- alias_method :inspect, :key ## note: add inspect debug support change debug output to string!!
171
-
172
-
173
-
174
- def to_path( format=:default )
175
- case format
176
- when :default, :short, :s ## e.g. 1999-00 or 2019-20
177
- to_s( :short, sep: '-' )
178
- when :long, :l ## e.g. 1999-2000 or 2019-2000
179
- to_s( :long, sep: '-' )
180
- when :archive, :decade, :d ## e.g. 1990s/1999-00 or 2010s/2019-20
181
- "%3d0s/%s" % [@start_year / 10, to_s( :short, sep: '-' )]
182
- when :century, :c ## e.g. 1900s/1990-00 or 2000s/2019-20
183
- "%2d00s/%s" % [@start_year / 100, to_s( :short, sep: '-' )]
184
- else
185
- raise ArgumentError, "[Season.to_path] unsupported format >#{format}<"
186
- end
187
- end # method to_path
188
- alias_method :directory, :to_path ## keep "legacy" directory alias - why? why not?
189
- alias_method :path, :to_path
190
-
191
- end # class Season
192
-
193
-
194
-
195
- ### note: add a convenience "shortcut" season kernel method conversion method
196
- ## use like Season( '2012/3' ) or such
197
- module Kernel
198
- def Season( *args ) Season.convert( *args ); end
199
- end
data/test/test_season.rb DELETED
@@ -1,141 +0,0 @@
1
- ###
2
- # to run use
3
- # ruby -I ./lib -I ./test test/test_season.rb
4
-
5
-
6
- require 'helper'
7
-
8
- class TestSeason < MiniTest::Test
9
-
10
-
11
- def test_to_path
12
- assert_equal '2010-11', Season( '2010-11' ).to_path
13
- assert_equal '2010-11', Season( '2010-2011' ).to_path
14
- assert_equal '2010-11', Season( '2010/11' ).to_path
15
- assert_equal '2010-11', Season( '2010/1' ).to_path
16
- assert_equal '2010-11', Season( '2010/2011' ).to_path
17
- assert_equal '2010', Season( '2010' ).to_path
18
-
19
- assert_equal '2010-11', Season( 2010, 2011 ).to_path
20
- assert_equal '2010-11', Season( 2010_2011 ).to_path
21
- assert_equal '2010-11', Season( 20102011 ).to_path
22
- assert_equal '2010-11', Season( 201011 ).to_path
23
- assert_equal '2010-11', Season( 20101 ).to_path
24
- assert_equal '2010', Season( 2010 ).to_path
25
-
26
- assert_equal '2010s/2010-11', Season( '2010-11' ).to_path( :decade )
27
- assert_equal '2010s/2010-11', Season( '2010-2011' ).to_path( :decade )
28
- assert_equal '2010s/2010', Season( '2010' ).to_path( :decade )
29
-
30
- assert_equal '1999-00', Season( '1999-00' ).to_path
31
- assert_equal '1999-00', Season( '1999-2000' ).to_path
32
- assert_equal '1990s/1999-00', Season( '1999-00' ).to_path( :decade )
33
- assert_equal '1990s/1999-00', Season( '1999-2000' ).to_path( :decade )
34
-
35
- assert_equal '2000s/2010-11', Season( '2010-11' ).to_path( :century )
36
- assert_equal '2000s/2010-11', Season( '2010-2011' ).to_path( :century )
37
- assert_equal '2000s/2010', Season( '2010' ).to_path( :century )
38
-
39
- assert_equal '1900s/1999-00', Season( '1999-00' ).to_path( :century )
40
- assert_equal '1900s/1999-00', Season( '1999-2000' ).to_path( :century )
41
- end # method test_to_path
42
-
43
-
44
- def test_key
45
- assert_equal '2010/11', Season( '2010-11' ).key
46
- assert_equal '2010/11', Season( '2010-2011' ).key
47
- assert_equal '2010/11', Season( '2010/11' ).key
48
- assert_equal '2010/11', Season( '2010/1' ).key
49
- assert_equal '2010/11', Season( '2010/2011' ).key
50
- assert_equal '2010', Season( '2010' ).key
51
-
52
- assert_equal '1999/00', Season( '1999-00' ).key
53
- assert_equal '1999/00', Season( '1999-2000' ).key
54
- end # method test_key
55
-
56
-
57
- def test_years
58
- [Season( '1999-00' ),
59
- Season( '1999/00' ),
60
- Season( '1999/2000' ),
61
- Season( 1999, 2000 ),
62
- Season( 1999_00 ), ## allow "hacky" shortcuts - why? why not?
63
- Season( 1999_2000 ),
64
- ].each do |season|
65
- assert_equal 1999, season.start_year
66
- assert_equal 2000, season.end_year
67
- end
68
-
69
- [Season( '2010/1' ),
70
- Season( '2010/11' ),
71
- Season( 201011 ), ## allow "hacky" shortcuts - why? why not?
72
- Season( 20102011 ),
73
- ].each do |season|
74
- assert_equal 2010, season.start_year
75
- assert_equal 2011, season.end_year
76
- end
77
-
78
- [Season( '1999' ),
79
- Season( 1999 ),
80
- ].each do |season|
81
- assert_equal 1999, season.start_year
82
- assert_equal 1999, season.end_year
83
- end
84
-
85
- [Season( '2010' ),
86
- Season( 2010 ),
87
- ].each do |season|
88
- assert_equal 2010, season.start_year
89
- assert_equal 2010, season.end_year
90
- end
91
- end
92
-
93
-
94
- def test_prev
95
- assert_equal '2009/10', Season( '2010-11' ).prev.key
96
- assert_equal '2009/10', Season( '2010-2011' ).prev.key
97
- assert_equal '2009', Season( '2010' ).prev.key
98
-
99
- assert_equal '1998/99', Season( '1999-00' ).prev.key
100
- assert_equal '1998/99', Season( '1999-2000' ).prev.key
101
- end
102
-
103
- def test_next
104
- assert_equal '2009/10', Season( '2008-09' ).next.key
105
- assert_equal '2009/10', Season( '2008-2009' ).next.key
106
- assert_equal '2009', Season( '2008' ).next.key
107
-
108
- assert_equal '1998/99', Season( '1997-98' ).next.key
109
- assert_equal '1998/99', Season( '1997-1998' ).next.key
110
- end
111
-
112
-
113
- def test_range
114
- s2010 = Season( '2010' )..Season( '2019' )
115
- pp s2010.to_a
116
- # => [2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019]
117
-
118
- s2010 = Season( '2010-11')..Season( '2019-20')
119
- pp s2010.to_a
120
- # => [2010/11, 2011/12, 2012/13, 2013/14, 2014/15,
121
- # 2015/16, 2016/17, 2017/18, 2018/19, 2019/20]
122
-
123
- puts s2010 === Season( '2015-16' ) # true
124
- puts s2010 === Season( '2015' ) # !!!! false - why? if using >= <=
125
- puts s2010 === Season( '1999-00' ) # false
126
- puts s2010 === Season( '2020-21' ) # false
127
-
128
- puts
129
- puts s2010.include? Season( '2015-16' ) # true
130
- puts s2010.include? Season( '2015' ) # !!! false
131
- puts s2010.include? Season( '1999-00' ) # false
132
-
133
- assert_equal true, Season( '2010-11' ) < Season( '2015' )
134
- assert_equal true, Season( '2015' ) < Season( '2019-20' )
135
-
136
- assert_equal false, Season( '2015' ) == Season( '2015-16' )
137
- assert_equal true, Season( '2015' ) < Season( '2015-16' )
138
- assert_equal true, Season( '2015' ) == Season( '2015' )
139
- end
140
-
141
- end # class TestSeason