sportdb-structs 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,84 +1,84 @@
1
-
2
- module Sports
3
-
4
-
5
- class TeamUsage
6
-
7
- class TeamUsageLine ## nested class
8
- attr_accessor :team,
9
- :matches, ## number of matches (played),
10
- :seasons, ## (optianl) array of seasons, use seasons.size for count
11
- :levels ## (optional) hash of levels (holds mapping level to TeamUsageLine)
12
-
13
- def initialize( team )
14
- @team = team
15
-
16
- @matches = 0
17
- @seasons = []
18
- @levels = {}
19
- end
20
- end # (nested) class TeamUsageLine
21
-
22
-
23
-
24
- def initialize( opts={} )
25
- @lines = {} # StandingsLines cached by team name/key
26
- end
27
-
28
-
29
- def update( matches, season: '?', level: nil )
30
- ## convenience - update all matches at once
31
- matches.each_with_index do |match,i| # note: index(i) starts w/ zero (0)
32
- update_match( match, season: season, level: level )
33
- end
34
- self # note: return self to allow chaining
35
- end
36
-
37
- def to_a
38
- ## return lines; sort
39
-
40
- # build array from hash
41
- ary = []
42
- @lines.each do |k,v|
43
- ary << v
44
- end
45
-
46
- ## for now sort just by name (a-z)
47
- ary.sort! do |l,r|
48
- ## note: reverse order (thus, change l,r to r,l)
49
- l.team <=> r.team
50
- end
51
-
52
- ary
53
- end # to_a
54
-
55
-
56
- private
57
- def update_match( m, season: '?', level: nil ) ## add a match
58
-
59
- line1 = @lines[ m.team1 ] ||= TeamUsageLine.new( m.team1 )
60
- line2 = @lines[ m.team2 ] ||= TeamUsageLine.new( m.team2 )
61
-
62
- line1.matches +=1
63
- line2.matches +=1
64
-
65
- ## include season if not seen before (allow season in multiple files!!!)
66
- line1.seasons << season unless line1.seasons.include?( season )
67
- line2.seasons << season unless line2.seasons.include?( season )
68
-
69
- if level
70
- line1_level = line1.levels[ level ] ||= TeamUsageLine.new( m.team1 )
71
- line2_level = line2.levels[ level ] ||= TeamUsageLine.new( m.team2 )
72
-
73
- line1_level.matches +=1
74
- line2_level.matches +=1
75
-
76
- line1_level.seasons << season unless line1_level.seasons.include?( season )
77
- line2_level.seasons << season unless line2_level.seasons.include?( season )
78
- end
79
- end # method update_match
80
-
81
-
82
- end # class TeamUsage
83
-
84
- end # module Sports
1
+
2
+ module Sports
3
+
4
+
5
+ class TeamUsage
6
+
7
+ class TeamUsageLine ## nested class
8
+ attr_accessor :team,
9
+ :matches, ## number of matches (played),
10
+ :seasons, ## (optianl) array of seasons, use seasons.size for count
11
+ :levels ## (optional) hash of levels (holds mapping level to TeamUsageLine)
12
+
13
+ def initialize( team )
14
+ @team = team
15
+
16
+ @matches = 0
17
+ @seasons = []
18
+ @levels = {}
19
+ end
20
+ end # (nested) class TeamUsageLine
21
+
22
+
23
+
24
+ def initialize( opts={} )
25
+ @lines = {} # StandingsLines cached by team name/key
26
+ end
27
+
28
+
29
+ def update( matches, season: '?', level: nil )
30
+ ## convenience - update all matches at once
31
+ matches.each_with_index do |match,i| # note: index(i) starts w/ zero (0)
32
+ update_match( match, season: season, level: level )
33
+ end
34
+ self # note: return self to allow chaining
35
+ end
36
+
37
+ def to_a
38
+ ## return lines; sort
39
+
40
+ # build array from hash
41
+ ary = []
42
+ @lines.each do |k,v|
43
+ ary << v
44
+ end
45
+
46
+ ## for now sort just by name (a-z)
47
+ ary.sort! do |l,r|
48
+ ## note: reverse order (thus, change l,r to r,l)
49
+ l.team <=> r.team
50
+ end
51
+
52
+ ary
53
+ end # to_a
54
+
55
+
56
+ private
57
+ def update_match( m, season: '?', level: nil ) ## add a match
58
+
59
+ line1 = @lines[ m.team1 ] ||= TeamUsageLine.new( m.team1 )
60
+ line2 = @lines[ m.team2 ] ||= TeamUsageLine.new( m.team2 )
61
+
62
+ line1.matches +=1
63
+ line2.matches +=1
64
+
65
+ ## include season if not seen before (allow season in multiple files!!!)
66
+ line1.seasons << season unless line1.seasons.include?( season )
67
+ line2.seasons << season unless line2.seasons.include?( season )
68
+
69
+ if level
70
+ line1_level = line1.levels[ level ] ||= TeamUsageLine.new( m.team1 )
71
+ line2_level = line2.levels[ level ] ||= TeamUsageLine.new( m.team2 )
72
+
73
+ line1_level.matches +=1
74
+ line2_level.matches +=1
75
+
76
+ line1_level.seasons << season unless line1_level.seasons.include?( season )
77
+ line2_level.seasons << season unless line2_level.seasons.include?( season )
78
+ end
79
+ end # method update_match
80
+
81
+
82
+ end # class TeamUsage
83
+
84
+ end # module Sports
@@ -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 = 2
7
+ PATCH = 3
8
8
  VERSION = [MAJOR,MINOR,PATCH].join('.')
9
9
 
10
10
  def self.version
data/test/helper.rb CHANGED
@@ -1,13 +1,13 @@
1
- ## note: use the local version of sportdb gems
2
- $LOAD_PATH.unshift( File.expand_path( '../date-formats/lib' ))
3
- $LOAD_PATH.unshift( File.expand_path( '../score-formats/lib' ))
4
- $LOAD_PATH.unshift( File.expand_path( '../sportdb-langs/lib' ))
5
-
6
-
7
- ## minitest setup
8
- require 'minitest/autorun'
9
-
10
-
11
- ## our own code
12
- require 'sportdb/structs'
13
-
1
+ ## note: use the local version of sportdb gems
2
+ $LOAD_PATH.unshift( File.expand_path( '../date-formats/lib' ))
3
+ $LOAD_PATH.unshift( File.expand_path( '../score-formats/lib' ))
4
+ $LOAD_PATH.unshift( File.expand_path( '../sportdb-langs/lib' ))
5
+
6
+
7
+ ## minitest setup
8
+ require 'minitest/autorun'
9
+
10
+
11
+ ## our own code
12
+ require 'sportdb/structs'
13
+
@@ -1,57 +1,57 @@
1
- ###
2
- # to run use
3
- # ruby -I ./lib -I ./test test/test_match_status_parser.rb
4
-
5
-
6
- require 'helper'
7
-
8
-
9
- class TestMatchStatusParser < MiniTest::Test
10
-
11
- Status = SportDb::Status
12
- StatusParser = SportDb::StatusParser
13
-
14
- def test_find
15
- [['awarded [cancelled] canceled [ddd]', Status::CANCELLED],
16
- ['awarded [bbb; canceled] canceled [awarded; comments] eeee', Status::AWARDED],
17
- ['aaa bbb ccc ddd eeee', nil],
18
- ].each do |rec|
19
- line = rec[0]
20
- status_exp = rec[1]
21
- puts "line (before): >#{line}<"
22
- status = StatusParser.find!( line )
23
- puts "status: >#{status}<"
24
- puts "line (after): >#{line}<"
25
- puts
26
-
27
- if status_exp.nil?
28
- assert_nil status
29
- else
30
- assert_equal status_exp, status
31
- end
32
- end
33
- end # method test_find
34
-
35
- def test_parse
36
- [['cancelled ddd', Status::CANCELLED],
37
- ['CANCELLED', Status::CANCELLED],
38
- ['can.', Status::CANCELLED],
39
- ['awarded; comments', Status::AWARDED],
40
- ['awd. - comments', Status::AWARDED],
41
- ['aaa bbb ccc ddd eeee', nil],
42
- ].each do |rec|
43
- str = rec[0]
44
- status_exp = rec[1]
45
- status = StatusParser.parse( str )
46
-
47
- if status_exp.nil? ## for "silencing" minitest warning - Use assert_nil if expecting nil
48
- assert_nil status
49
- else
50
- assert_equal status_exp, status
51
- end
52
- end
53
- end
54
-
55
- end # class TestMatchStatusParser
56
-
57
-
1
+ ###
2
+ # to run use
3
+ # ruby -I ./lib -I ./test test/test_match_status_parser.rb
4
+
5
+
6
+ require 'helper'
7
+
8
+
9
+ class TestMatchStatusParser < MiniTest::Test
10
+
11
+ Status = SportDb::Status
12
+ StatusParser = SportDb::StatusParser
13
+
14
+ def test_find
15
+ [['awarded [cancelled] canceled [ddd]', Status::CANCELLED],
16
+ ['awarded [bbb; canceled] canceled [awarded; comments] eeee', Status::AWARDED],
17
+ ['aaa bbb ccc ddd eeee', nil],
18
+ ].each do |rec|
19
+ line = rec[0]
20
+ status_exp = rec[1]
21
+ puts "line (before): >#{line}<"
22
+ status = StatusParser.find!( line )
23
+ puts "status: >#{status}<"
24
+ puts "line (after): >#{line}<"
25
+ puts
26
+
27
+ if status_exp.nil?
28
+ assert_nil status
29
+ else
30
+ assert_equal status_exp, status
31
+ end
32
+ end
33
+ end # method test_find
34
+
35
+ def test_parse
36
+ [['cancelled ddd', Status::CANCELLED],
37
+ ['CANCELLED', Status::CANCELLED],
38
+ ['can.', Status::CANCELLED],
39
+ ['awarded; comments', Status::AWARDED],
40
+ ['awd. - comments', Status::AWARDED],
41
+ ['aaa bbb ccc ddd eeee', nil],
42
+ ].each do |rec|
43
+ str = rec[0]
44
+ status_exp = rec[1]
45
+ status = StatusParser.parse( str )
46
+
47
+ if status_exp.nil? ## for "silencing" minitest warning - Use assert_nil if expecting nil
48
+ assert_nil status
49
+ else
50
+ assert_equal status_exp, status
51
+ end
52
+ end
53
+ end
54
+
55
+ end # class TestMatchStatusParser
56
+
57
+
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.2
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-11-22 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
@@ -120,14 +120,14 @@ dependencies:
120
120
  requirements:
121
121
  - - "~>"
122
122
  - !ruby/object:Gem::Version
123
- version: '3.22'
123
+ version: '3.23'
124
124
  type: :development
125
125
  prerelease: false
126
126
  version_requirements: !ruby/object:Gem::Requirement
127
127
  requirements:
128
128
  - - "~>"
129
129
  - !ruby/object:Gem::Version
130
- version: '3.22'
130
+ version: '3.23'
131
131
  description: sportdb-structs - sport data structures for matches, scores, leagues,
132
132
  seasons, rounds, groups, teams, clubs and more
133
133
  email: opensport@googlegroups.com
@@ -169,7 +169,7 @@ homepage: https://github.com/sportdb/sport.db
169
169
  licenses:
170
170
  - Public Domain
171
171
  metadata: {}
172
- post_install_message:
172
+ post_install_message:
173
173
  rdoc_options:
174
174
  - "--main"
175
175
  - README.md
@@ -186,9 +186,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
186
  - !ruby/object:Gem::Version
187
187
  version: '0'
188
188
  requirements: []
189
- rubyforge_project:
190
- rubygems_version: 2.5.2
191
- signing_key:
189
+ rubygems_version: 3.3.7
190
+ signing_key:
192
191
  specification_version: 4
193
192
  summary: sportdb-structs - sport data structures for matches, scores, leagues, seasons,
194
193
  rounds, groups, teams, clubs and more