sportdb-structs 0.2.0 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '009da80615ac77d643529d2feee7692ca31ce2c07c5f1dd45cf2667558af4b90'
4
- data.tar.gz: 7368f410cfc3b4fa0af288c20399c1244841518cf5598ff443dcf17aaa881501
3
+ metadata.gz: c966a814cdade0a21ea6453fc1900bfc8c384a8ceecaa34dc158e6d60bfd39b5
4
+ data.tar.gz: 5086fb02b42d15da5f93780121de2ba77012de34be0ff51134a06b97136c5f00
5
5
  SHA512:
6
- metadata.gz: 56acdb1dc22c5b70f51c398e1ae912ff6bcbf50f021391efa5eba75d3ddeb4c1d069255fd715a891f6c4451f25f4c0212eb8769bd129755ede88ca322cd4e4e6
7
- data.tar.gz: 35dcad60e6c784859d5c7218e4771ec5979cb4a07b1e07ba6f598e64fc968c1cfd75ee5e48f2c22996fa570a37292051b8f4f4e195ea2b9527ecfceef4753b6c
6
+ metadata.gz: fb26346fb4a76ced79e7bbb4518e5bcdb26b7128583a17ff963e3b1bc8c2198d41115babfadb06fc9331fb21c5b06059162510961f330cce58dee96aa7e16c17
7
+ data.tar.gz: b2d9c498d7cd119637e71b546e84d586329dd6e9186ffaaf8c93d27d5a9e3b2f4b8e1c37a69f09cbdfbc98f94ffb695b632c91c81c35c6c6dddae3c0d60e3c06
data/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- ### 0.2.0
1
+ ### 0.3.0
2
2
 
3
3
  ### 0.0.1 / 2020-08-24
4
4
 
data/Manifest.txt CHANGED
@@ -3,20 +3,15 @@ Manifest.txt
3
3
  README.md
4
4
  Rakefile
5
5
  lib/sportdb/structs.rb
6
- lib/sportdb/structs/config.rb
7
- lib/sportdb/structs/goal_parser_csv.rb
8
- lib/sportdb/structs/match_parser_csv.rb
9
- lib/sportdb/structs/match_status_parser.rb
10
- lib/sportdb/structs/name_helper.rb
11
- lib/sportdb/structs/structs/country.rb
12
- lib/sportdb/structs/structs/goal.rb
13
- lib/sportdb/structs/structs/ground.rb
14
- lib/sportdb/structs/structs/group.rb
15
- lib/sportdb/structs/structs/league.rb
16
- lib/sportdb/structs/structs/match.rb
17
- lib/sportdb/structs/structs/matchlist.rb
18
- lib/sportdb/structs/structs/round.rb
19
- lib/sportdb/structs/structs/standings.rb
20
- lib/sportdb/structs/structs/team.rb
21
- lib/sportdb/structs/structs/team_usage.rb
6
+ lib/sportdb/structs/country.rb
7
+ lib/sportdb/structs/goal.rb
8
+ lib/sportdb/structs/ground.rb
9
+ lib/sportdb/structs/group.rb
10
+ lib/sportdb/structs/league.rb
11
+ lib/sportdb/structs/match.rb
12
+ lib/sportdb/structs/matchlist.rb
13
+ lib/sportdb/structs/round.rb
14
+ lib/sportdb/structs/standings.rb
15
+ lib/sportdb/structs/team.rb
16
+ lib/sportdb/structs/team_usage.rb
22
17
  lib/sportdb/structs/version.rb
data/Rakefile CHANGED
@@ -20,12 +20,9 @@ Hoe.spec 'sportdb-structs' do
20
20
  self.licenses = ['Public Domain']
21
21
 
22
22
  self.extra_deps = [
23
- ['alphabets', '>= 1.0.0'],
24
- ['date-formats', '>= 1.0.2'],
23
+ ['alphabets', '>= 1.0.2'],
25
24
  ['score-formats', '>= 0.1.1'],
26
25
  ['season-formats', '>= 0.0.1'],
27
- ['csvreader', '>= 1.2.4'],
28
- ['sportdb-langs', '>= 0.1.1'],
29
26
  ]
30
27
 
31
28
  self.spec_extras = {
@@ -47,6 +47,15 @@ class Country
47
47
  @tags = tags
48
48
  end
49
49
 
50
+ def pretty_print( printer )
51
+ buf = String.new
52
+ buf << "<Country: #{@key} - #{@name} (#{@code})"
53
+ buf << "|#{@alt_names.join('|')}" if @alt_names && !@alt_names.empty?
54
+ buf << ", #{@tags.join('|')})" if @tags && !@tags.empty?
55
+ buf << ">"
56
+
57
+ printer.text( buf )
58
+ end
50
59
  end # class Country
51
60
 
52
61
  end # module Sports
@@ -0,0 +1,78 @@
1
+
2
+ module Sports
3
+
4
+ class Goal ### nested (non-freestanding) inside match (match is parent)
5
+ attr_reader :score1,
6
+ :score2,
7
+ :team,
8
+ :player,
9
+ :minute,
10
+ :offset,
11
+ :owngoal,
12
+ :penalty,
13
+ :notes
14
+
15
+ ## add alias for player => name - why? why not?
16
+ alias_method :name, :player
17
+
18
+
19
+ def owngoal?() @owngoal==true; end
20
+ def penalty?() @penalty==true; end
21
+ def team1?() @team == 1; end
22
+ def team2?() @team == 2; end
23
+
24
+
25
+ ## note: make score1,score2 optional for now !!!!
26
+ def initialize( team:,
27
+ player:,
28
+ minute:,
29
+ offset: nil,
30
+ owngoal: false,
31
+ penalty: false,
32
+ score1: nil,
33
+ score2: nil,
34
+ notes: nil
35
+ )
36
+ @score1 = score1
37
+ @score2 = score2
38
+
39
+ @team = team # 1 or 2
40
+ @player = player
41
+ @minute = minute
42
+ @offset = offset
43
+ @owngoal = owngoal
44
+ @penalty = penalty
45
+ @notes = notes
46
+ end
47
+
48
+ def state
49
+ [@score1, @score2,
50
+ @team,
51
+ @player, @minute, @offset, @owngoal, @penalty,
52
+ @notes
53
+ ]
54
+ end
55
+
56
+ def ==(o)
57
+ o.class == self.class && o.state == state
58
+ end
59
+
60
+ def pretty_print( printer )
61
+ buf = String.new
62
+ buf << "<Goal: #{@score1 ? @score1 : '?'}-#{@score2 ? @score2 : '?'}"
63
+ buf << " #{@player} #{@minute}"
64
+ buf << "+#{@offset}" if @offset && @offset > 0
65
+ buf << "'"
66
+ buf << " (o.g.)" if @owngoal
67
+ buf << " (pen.)" if @penalty
68
+ buf << " for #{@team}" ### team 1 or 2 - use home/away
69
+ buf << " -- #{@notes}" if @notes
70
+ buf << ">"
71
+
72
+ printer.text( buf )
73
+ end
74
+ end # class Goal
75
+
76
+
77
+ end # module Sports
78
+
@@ -11,14 +11,14 @@ class Group
11
11
  @teams = teams
12
12
  end
13
13
 
14
- def pretty_print( printer )
15
- ## todo/check - how to display/format key - use () or not - why? why not?
14
+ def pretty_print( printer )
15
+ ## todo/check - how to display/format key - use () or not - why? why not?
16
16
  buf = String.new
17
17
  buf << "<Group: #{@key ? @key : '?'} - #{@name} "
18
18
  buf << @teams.pretty_print_inspect
19
19
  buf << ">"
20
-
21
- printer.text( buf )
20
+
21
+ printer.text( buf )
22
22
  end
23
23
  end # class Group
24
24
  end # module Sports
@@ -27,6 +27,35 @@ class League
27
27
  alias_method :club?, :clubs?
28
28
  alias_method :national_team?, :national_teams?
29
29
 
30
+ =begin
31
+ @alt_names=[],
32
+ @clubs=true,
33
+ @country=<Country: at - Austria (AUT)|Österreich [de], fifa|uefa)>,
34
+ @intl=false,
35
+ @key="at.1",
36
+ @name="Bundesliga">,
37
+ =end
38
+
39
+ def pretty_print( printer )
40
+ buf = String.new
41
+ buf << "<League"
42
+ buf << " INTL" if @intl
43
+ buf << if @clubs
44
+ " CLUBS"
45
+ else
46
+ " NATIONAL TEAMS"
47
+ end
48
+ buf << ": #{@key} - #{@name}"
49
+ buf << "|#{@alt_names.join('|')}" if @alt_names && !@alt_names.empty?
50
+ buf << ", #{@country.name} (#{@country.code})" if @country
51
+ buf << ">"
52
+
53
+ printer.text( buf )
54
+ end
55
+
56
+
57
+
58
+
30
59
  end # class League
31
60
 
32
61
  end # module Sports
@@ -4,7 +4,8 @@ module Sports
4
4
 
5
5
  class Match
6
6
 
7
- attr_reader :date,
7
+ attr_reader :num,
8
+ :date,
8
9
  :time,
9
10
  :team1, :team2, ## todo/fix: use team1_name, team2_name or similar - for compat with db activerecord version? why? why not?
10
11
  :score1, :score2, ## full time
@@ -37,7 +38,10 @@ class Match
37
38
  update( **kwargs ) unless kwargs.empty?
38
39
  end
39
40
 
41
+
40
42
  def update( **kwargs )
43
+ @num = kwargs[:num] if kwargs.has_key?( :num )
44
+
41
45
  ## note: check with has_key? because value might be nil!!!
42
46
  @date = kwargs[:date] if kwargs.has_key?( :date )
43
47
  @time = kwargs[:time] if kwargs.has_key?( :time )
@@ -3,7 +3,7 @@ module SportDb
3
3
  module Module
4
4
  module Structs
5
5
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
6
- MINOR = 2
6
+ MINOR = 3
7
7
  PATCH = 0
8
8
  VERSION = [MAJOR,MINOR,PATCH].join('.')
9
9
 
@@ -1,85 +1,32 @@
1
1
  ## 3rd party gems
2
- require 'alphabets' # downcase_i18n, unaccent, variants, ...
3
- require 'date/formats' # DateFormats.parse, find!, ...
2
+ require 'alphabets' # unaccent, downcase_i18n, variants, ...
4
3
  require 'season/formats' # Season.parse, ...
5
4
  require 'score/formats'
6
- require 'csvreader'
7
-
8
-
9
- def read_csv( path, sep: nil,
10
- symbolize_names: nil )
11
- opts = {}
12
- opts[:sep] = sep if sep
13
- opts[:header_converters] = :symbol if symbolize_names
14
-
15
- CsvHash.read( path, **opts )
16
- end
17
-
18
- def parse_csv( txt, sep: nil,
19
- symbolize_names: nil )
20
- opts = {}
21
- opts[:sep] = sep if sep
22
- opts[:header_converters] = :symbol if symbolize_names
23
-
24
- CsvHash.parse( txt, **opts )
25
- end
26
-
27
-
28
-
29
- ## more sportdb libs/gems
30
- require 'sportdb/langs'
31
-
32
-
33
- ## todo/fix: move shortcut up to sportdb/langs!!!
34
- module SportDb
35
- Logging = LogUtils::Logging ## logging machinery shortcut; use LogUtils for now
36
- end
37
-
38
- ## let's put test configuration in its own namespace / module
39
- module SportDb
40
- class Test ## todo/check: works with module too? use a module - why? why not?
41
-
42
- ####
43
- # todo/fix: find a better way to configure shared test datasets - why? why not?
44
- # note: use one-up (..) directory for now as default - why? why not?
45
- def self.data_dir() @data_dir ||= '../test'; end
46
- def self.data_dir=( path ) @data_dir = path; end
47
- end
48
- end # module SportDb
49
-
50
-
51
- ## todo/check: move up config to langs too - why? why not?
52
-
53
-
54
5
 
55
6
 
56
7
  ###
57
8
  # our own code
58
- require 'sportdb/structs/version' # let version always go first
59
- require 'sportdb/structs/config' # let "global" config "framework" go next - why? why not?
60
-
61
-
62
- require 'sportdb/structs/name_helper'
9
+ require_relative 'structs/version' # let version always go first
63
10
 
64
- require 'sportdb/structs/structs/country'
65
- require 'sportdb/structs/structs/league'
66
- require 'sportdb/structs/structs/team'
67
- require 'sportdb/structs/structs/round'
68
- require 'sportdb/structs/structs/group'
69
- require 'sportdb/structs/structs/goal'
70
- require 'sportdb/structs/structs/match'
71
- require 'sportdb/structs/structs/matchlist'
72
- require 'sportdb/structs/structs/standings'
73
- require 'sportdb/structs/structs/team_usage'
11
+ require_relative 'structs/country'
12
+ require_relative 'structs/league'
13
+ require_relative 'structs/team'
14
+ require_relative 'structs/ground'
15
+ require_relative 'structs/round'
16
+ require_relative 'structs/group'
17
+ require_relative 'structs/goal'
18
+ require_relative 'structs/match'
74
19
 
75
- require 'sportdb/structs/structs/ground'
20
+ require_relative 'structs/matchlist'
21
+ require_relative 'structs/standings'
22
+ require_relative 'structs/team_usage'
76
23
 
77
24
 
78
25
  ##
79
26
  ## todo/fix - move "inline" player to structs/player file !!!!
80
27
 
81
28
  module Sports
82
- ### note - own classes for National(Squad)Player and
29
+ ### note - own classes for National(Squad)Player and
83
30
  ## Club(Squad)Player and such in use
84
31
 
85
32
  class Player
@@ -94,7 +41,7 @@ class Player
94
41
 
95
42
  def initialize( name:,
96
43
  pos: nil,
97
- nat: nil,
44
+ nat: nil,
98
45
  height: nil,
99
46
  birthdate: nil,
100
47
  birthplace: nil )
@@ -112,51 +59,6 @@ end # module Sports
112
59
 
113
60
 
114
61
 
115
- require 'sportdb/structs/match_status_parser'
116
- require 'sportdb/structs/match_parser_csv'
117
- require 'sportdb/structs/goal_parser_csv'
118
-
119
-
120
-
121
-
122
- ### add convenience shortcut helpers
123
- module Sports
124
- class Match
125
- def self.read_csv( path, headers: nil, filters: nil, converters: nil, sep: nil )
126
- SportDb::CsvMatchParser.read( path,
127
- headers: headers,
128
- filters: filters,
129
- converters: converters,
130
- sep: sep )
131
- end
132
-
133
- def self.parse_csv( txt, headers: nil, filters: nil, converters: nil, sep: nil )
134
- SportDb::CsvMatchParser.parse( txt,
135
- headers: headers,
136
- filters: filters,
137
- converters: converters,
138
- sep: sep )
139
- end
140
- end # class Match
141
- end # module Sports
142
-
143
-
144
-
145
- module Sports
146
- ## lets you use
147
- ## Sports.configure do |config|
148
- ## config.lang = 'it'
149
- ## end
150
-
151
- ## note: just forward to SportDb::Import configuration!!!!!
152
- ## keep Sports module / namespace "clean"
153
- ## that is, only include data structures (e.g. Match,League,etc) for now - why? why not?
154
- def self.configure() yield( config ); end
155
- def self.config() SportDb::Import.config; end
156
- end # module Sports
157
-
158
-
159
-
160
62
  #####
161
63
  # note: add Sport and Football convenience alias - why? why not?
162
64
  Sport = Sports
@@ -165,7 +67,5 @@ Football = Sports
165
67
 
166
68
 
167
69
 
168
-
169
70
  puts SportDb::Module::Structs.banner # say hello
170
71
 
171
-
metadata CHANGED
@@ -1,31 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sportdb-structs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-22 00:00:00.000000000 Z
11
+ date: 2024-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: alphabets
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: 1.0.0
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: 1.0.0
27
- - !ruby/object:Gem::Dependency
28
- name: date-formats
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - ">="
@@ -66,34 +52,6 @@ dependencies:
66
52
  - - ">="
67
53
  - !ruby/object:Gem::Version
68
54
  version: 0.0.1
69
- - !ruby/object:Gem::Dependency
70
- name: csvreader
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: 1.2.4
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: 1.2.4
83
- - !ruby/object:Gem::Dependency
84
- name: sportdb-langs
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: 0.1.1
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: 0.1.1
97
55
  - !ruby/object:Gem::Dependency
98
56
  name: rdoc
99
57
  requirement: !ruby/object:Gem::Requirement
@@ -143,22 +101,17 @@ files:
143
101
  - README.md
144
102
  - Rakefile
145
103
  - lib/sportdb/structs.rb
146
- - lib/sportdb/structs/config.rb
147
- - lib/sportdb/structs/goal_parser_csv.rb
148
- - lib/sportdb/structs/match_parser_csv.rb
149
- - lib/sportdb/structs/match_status_parser.rb
150
- - lib/sportdb/structs/name_helper.rb
151
- - lib/sportdb/structs/structs/country.rb
152
- - lib/sportdb/structs/structs/goal.rb
153
- - lib/sportdb/structs/structs/ground.rb
154
- - lib/sportdb/structs/structs/group.rb
155
- - lib/sportdb/structs/structs/league.rb
156
- - lib/sportdb/structs/structs/match.rb
157
- - lib/sportdb/structs/structs/matchlist.rb
158
- - lib/sportdb/structs/structs/round.rb
159
- - lib/sportdb/structs/structs/standings.rb
160
- - lib/sportdb/structs/structs/team.rb
161
- - lib/sportdb/structs/structs/team_usage.rb
104
+ - lib/sportdb/structs/country.rb
105
+ - lib/sportdb/structs/goal.rb
106
+ - lib/sportdb/structs/ground.rb
107
+ - lib/sportdb/structs/group.rb
108
+ - lib/sportdb/structs/league.rb
109
+ - lib/sportdb/structs/match.rb
110
+ - lib/sportdb/structs/matchlist.rb
111
+ - lib/sportdb/structs/round.rb
112
+ - lib/sportdb/structs/standings.rb
113
+ - lib/sportdb/structs/team.rb
114
+ - lib/sportdb/structs/team_usage.rb
162
115
  - lib/sportdb/structs/version.rb
163
116
  homepage: https://github.com/sportdb/sport.db
164
117
  licenses:
@@ -1,39 +0,0 @@
1
- module SportDb
2
- module Import
3
-
4
- class Configuration
5
- ##
6
- ## todo: allow configure of countries_dir like clubs_dir
7
- ## "fallback" and use a default built-in world/countries.txt
8
-
9
- ## note: catalog defined/added in sports-catalogs gem!!!
10
- ## attr_accessor :catalog
11
-
12
- attr_reader :lang
13
- def lang=(value)
14
- ## check/todo: always use to_sym - why? needed?
15
- DateFormats.lang = value
16
- ScoreFormats.lang = value
17
- SportDb.lang.lang = value
18
-
19
- ## todo/fix: change SportDb.lang to SportDb.parser.lang
20
- ## or lang_parser or utils or someting !!!!
21
- ## use Sport.lang only as a read-only shortcut
22
- # a la catalog for config.lang!!!!
23
- end
24
-
25
- end # class Configuration
26
-
27
-
28
- ## lets you use
29
- ## SportDb::Import.configure do |config|
30
- ## config.lang = 'it'
31
- ## end
32
- def self.configure() yield( config ); end
33
-
34
- def self.config() @config ||= Configuration.new; end
35
-
36
-
37
- end # module Import
38
- end # module SportDb
39
-
@@ -1,28 +0,0 @@
1
-
2
- module SportDb
3
- class CsvGoalParser
4
-
5
-
6
- def self.read( path )
7
- txt = File.open( path, 'r:utf-8' ) {|f| f.read } ## note: make sure to use (assume) utf-8
8
- parse( txt )
9
- end
10
-
11
- def self.parse( txt )
12
- new( txt ).parse
13
- end
14
-
15
-
16
- def initialize( txt )
17
- @txt = txt
18
- end
19
-
20
- def parse
21
- rows = parse_csv( @txt )
22
- recs = rows.map { |row| Sports::GoalEvent.build( row ) }
23
- ## pp recs[0]
24
- recs
25
- end
26
-
27
- end # class CsvGoalParser
28
- end # module Sports