sportdb-sync 1.0.2 → 1.0.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
2
  SHA1:
3
- metadata.gz: 415893e89d2c9d1a8dfa9b493ecff8452095f94f
4
- data.tar.gz: 9e55c19b40ee247d6b3b9e286b9dc799fe95c5d7
3
+ metadata.gz: 7c47d454d68dbeb13a19af73d5ea67e82093a7f7
4
+ data.tar.gz: b6de1499660943410dd9f8c293d5ac3a1d99c0dd
5
5
  SHA512:
6
- metadata.gz: 4e4487b6d40e296e9de680f99cb331693ccff0aac5dc3d73a55cae418f6ba9410966da1542bfa090fefa3e60123ab5822745041ab132d0876e7d89fa44ae7da7
7
- data.tar.gz: b59e3712eb51503aee9cc7c56c604fd8c5b0513a75995b7ceefe383f67820cd25ab17f97bd32f1ca6e0dfdacab49f4333eaa5b6af82102198714f7429d0b9ea9
6
+ metadata.gz: cb7827d0b7fe557ae9988ce6145db9f28ad0a62ec4773c0c8e55558b5b26a007f3d487fee966252ad819182eb2caa228897b41b198eecf57eae424a86e11e4e4
7
+ data.tar.gz: a3821524471837e9f7d6fc4a4016d39abd733aaa0f0c9036932d2edfc27f810b8fb55d3a1364e070808c05ddc929cfe052d1a1bba9fd899799f8cea4a6adaafb
data/Rakefile CHANGED
@@ -21,7 +21,7 @@ Hoe.spec 'sportdb-sync' do
21
21
 
22
22
  self.extra_deps = [
23
23
  ['sportdb-config', '>= 1.0.4'],
24
- ['sportdb-models', '>= 1.19.0'],
24
+ ['sportdb-models', '>= 2.0.0'],
25
25
  ]
26
26
 
27
27
  self.spec_extras = {
@@ -50,8 +50,8 @@ module SportDb
50
50
  # finders
51
51
 
52
52
  def self.find_or_create( club )
53
- ## note: assume "canonical uniquie" names/titles for now for clubs
54
- rec = Model::Team.find_by( title: club.name )
53
+ ## note: assume "canonical uniquie" names for now for clubs
54
+ rec = Model::Team.find_by( name: club.name )
55
55
  if rec.nil?
56
56
 
57
57
  ## todo/fix: move auto-key gen to structs for re(use)!!!!!!
@@ -61,7 +61,7 @@ module SportDb
61
61
 
62
62
  attribs = {
63
63
  key: key,
64
- title: club.name,
64
+ name: club.name,
65
65
  country_id: Sync::Country.find_or_create( club.country ).id,
66
66
  club: true,
67
67
  national: false ## check -is default anyway - use - why? why not?
@@ -71,7 +71,7 @@ module SportDb
71
71
  attribs[:code] = club.code if club.code ## add code (abbreviation) if present
72
72
 
73
73
  if club.alt_names.empty? == false
74
- attribs[:synonyms] = club.alt_names.join('|')
74
+ attribs[:alt_names] = club.alt_names.join('|')
75
75
  end
76
76
 
77
77
  rec = Model::Team.create!( attribs )
@@ -79,8 +79,8 @@ module SportDb
79
79
  ## otherwise use 2017, 7, 1
80
80
  ## start_at use year and 7,1 e.g. Date.new( 2017, 7, 1 )
81
81
  ## hack: fix/todo1!!
82
- ## add "fake" start_at date for now
83
- attribs[:start_at] = if season.year? ## e.g. assume 2018 etc.
82
+ ## add "fake" start_date for now
83
+ attribs[:start_date] = if season.year? ## e.g. assume 2018 etc.
84
84
  Date.new( season.start_year, 1, 1 )
85
85
  else ## assume 2014/15 etc.
86
86
  Date.new( season.start_year, 7, 1 )
@@ -40,11 +40,8 @@ module SportDb
40
40
  def self.find_or_create( league )
41
41
  rec = find( league )
42
42
  if rec.nil?
43
- ## use title and not name - why? why not?
44
- ## quick fix: change name to title
45
-
46
43
  attribs = { key: league.key,
47
- title: league.name }
44
+ name: league.name }
48
45
 
49
46
  if league.country
50
47
  attribs[ :country_id ] = Sync::Country.find_or_create( league.country ).id
@@ -43,7 +43,7 @@ module SportDb
43
43
  rec = find( season )
44
44
  if rec.nil?
45
45
  attribs = { key: season.key,
46
- title: season.name }
46
+ name: season.name }
47
47
  rec = Model::Season.create!( attribs )
48
48
  end
49
49
  rec
@@ -6,14 +6,14 @@ module SportDb
6
6
 
7
7
  class NationalTeam
8
8
  def self.find_or_create( team )
9
- rec = Model::Team.find_by( title: team.name )
9
+ rec = Model::Team.find_by( name: team.name )
10
10
  if rec.nil?
11
11
  puts "add national team: #{team.key}, #{team.name}, #{team.country.name} (#{team.country.key})"
12
12
 
13
13
  ### note: key expected three or more lowercase letters a-z /\A[a-z]{3,}\z/
14
14
  attribs = {
15
15
  key: team.key, ## note: always use downcase fifa code for now!!!
16
- title: team.name,
16
+ name: team.name,
17
17
  code: team.code,
18
18
  country_id: Sync::Country.find_or_create( team.country ).id,
19
19
  club: false,
@@ -21,7 +21,7 @@ module SportDb
21
21
  }
22
22
 
23
23
  if team.alt_names.empty? == false
24
- attribs[:synonyms] = team.alt_names.join('|')
24
+ attribs[:alt_names] = team.alt_names.join('|')
25
25
  end
26
26
 
27
27
  rec = Model::Team.create!( attribs )
@@ -64,19 +64,19 @@ module SportDb
64
64
 
65
65
  class Round
66
66
  def self.find_or_create( round, event: )
67
- rec = Model::Round.find_by( title: round.title, event_id: event.id )
67
+ rec = Model::Round.find_by( name: round.name, event_id: event.id )
68
68
  if rec.nil?
69
69
  ## find last pos - check if it can be nil?
70
70
  max_pos = Model::Round.where( event_id: event.id ).maximum( 'pos' )
71
71
  max_pos = max_pos ? max_pos+1 : 1
72
72
 
73
73
  attribs = { event_id: event.id,
74
- title: round.title,
74
+ name: round.name,
75
75
  pos: max_pos
76
76
  }
77
77
 
78
78
  ## todo/fix: check if round has (optional) start or end date and add!!!
79
- ## attribs[ :start_at] = round.start_at.to_date
79
+ ## attribs[ :start_date] = round.start_date.to_date
80
80
 
81
81
  rec = Model::Round.create!( attribs )
82
82
  end
@@ -87,14 +87,14 @@ module SportDb
87
87
 
88
88
  class Group
89
89
  def self.find_or_create( group, event: )
90
- rec = Model::Group.find_by( title: group.title, event_id: event.id )
90
+ rec = Model::Group.find_by( name: group.name, event_id: event.id )
91
91
  if rec.nil?
92
92
  ## find last pos - check if it can be nil?
93
93
  max_pos = Model::Group.where( event_id: event.id ).maximum( 'pos' )
94
94
  max_pos = max_pos ? max_pos+1 : 1
95
95
 
96
96
  attribs = { event_id: event.id,
97
- title: group.title,
97
+ name: group.name,
98
98
  pos: max_pos
99
99
  }
100
100
 
@@ -109,7 +109,7 @@ module SportDb
109
109
 
110
110
  class Stage
111
111
  def self.find( name, event: )
112
- Model::Stage.find_by( title: name, event_id: event.id )
112
+ Model::Stage.find_by( name: name, event_id: event.id )
113
113
  end
114
114
  def self.find!( name, event: )
115
115
  rec = find( name, event: event )
@@ -125,10 +125,8 @@ module SportDb
125
125
  def self.find_or_create( name, event: )
126
126
  rec = find( name, event: event )
127
127
  if rec.nil?
128
- ## use title and not name - why? why not?
129
- ## quick fix: change name to title
130
128
  attribs = { event_id: event.id,
131
- title: name,
129
+ name: name,
132
130
  }
133
131
  rec = Model::Stage.create!( attribs )
134
132
  end
@@ -138,21 +136,21 @@ module SportDb
138
136
 
139
137
 
140
138
 
141
- class Match ## todo/check: add alias for Game class - why? why not?
139
+ class Match
142
140
  def self.create_or_update( match, event: )
143
141
  ## note: MUST find round, thus, use bang (!)
144
142
 
145
143
  ## todo/check: allow strings too - why? why not?
146
144
 
147
145
  ## query for round - allow string or round rec
148
- round_title = match.round.is_a?( String ) ? match.round : match.round.title
146
+ round_name = match.round.is_a?( String ) ? match.round : match.round.name
149
147
  round_rec = Model::Round.find_by!( event_id: event.id,
150
- title: round_title )
148
+ name: round_name )
151
149
 
152
150
  ## todo/check: allow fallback with db lookup if NOT found in cache - why? why not?
153
151
  ## or better use Sync::Team.find_or_create( team ) !!!!!!! to auto-create on first hit!
154
152
  ## || Team.find_or_create( team1 ) -- note: does NOT work for string (only recs) - what to do?
155
- ## || Model::Team.find_by!( title: team1_name )
153
+ ## || Model::Team.find_by!( name: team1_name )
156
154
  team1_name = match.team1.is_a?( String ) ? match.team1 : match.team1.name
157
155
  team1_rec = Team.cache[ team1_name ]
158
156
  team2_name = match.team2.is_a?( String ) ? match.team2 : match.team2.name
@@ -160,20 +158,20 @@ module SportDb
160
158
 
161
159
  ## check optional group (e.g. Group A, etc.)
162
160
  group_rec = if match.group
163
- group_title = match.group.is_a?( String ) ? match.group : match.group.title
161
+ group_name = match.group.is_a?( String ) ? match.group : match.group.name
164
162
  Model::Group.find_by!( event_id: event.id,
165
- title: group_title )
163
+ name: group_name )
166
164
  else
167
165
  nil
168
166
  end
169
167
 
170
168
 
171
- rec = Model::Game.find_by( round_id: round_rec.id,
169
+ rec = Model::Match.find_by( round_id: round_rec.id,
172
170
  team1_id: team1_rec.id,
173
171
  team2_id: team2_rec.id )
174
172
  if rec.nil?
175
173
  ## find last pos - check if it can be nil?
176
- max_pos = Model::Game.where( event_id: event.id ).maximum( 'pos' )
174
+ max_pos = Model::Match.where( event_id: event.id ).maximum( 'pos' )
177
175
  max_pos = max_pos ? max_pos+1 : 1
178
176
 
179
177
  attribs = { event_id: event.id, ## todo/fix: change to data struct too?
@@ -181,14 +179,14 @@ module SportDb
181
179
  team1_id: team1_rec.id,
182
180
  team2_id: team2_rec.id,
183
181
  pos: max_pos,
184
- play_at: match.date.to_date,
182
+ date: match.date.to_date, ## todo/fix: split and add date & time!!!!
185
183
  score1: match.score1,
186
184
  score2: match.score2,
187
185
  score1i: match.score1i,
188
186
  score2i: match.score2i }
189
187
  attribs[ :group_id ] = group_rec.id if group_rec
190
188
 
191
- rec = Model::Game.create!( attribs )
189
+ rec = Model::Match.create!( attribs )
192
190
  else
193
191
  # update - todo
194
192
  end
@@ -7,7 +7,7 @@ module Sync
7
7
 
8
8
  MAJOR = 1 ## todo: namespace inside version or something - why? why not??
9
9
  MINOR = 0
10
- PATCH = 2
10
+ PATCH = 3
11
11
  VERSION = [MAJOR,MINOR,PATCH].join('.')
12
12
 
13
13
  def self.version
@@ -14,25 +14,25 @@ class TestLeague < MiniTest::Test
14
14
 
15
15
  def test_search
16
16
  rec = League.search_or_create!( 'eng' )
17
- assert_equal 'Premier League', rec.title ## fix: add name alias (rename title to name!!)
17
+ assert_equal 'Premier League', rec.name
18
18
  assert_equal 'eng.1', rec.key
19
19
  assert_equal 'eng', rec.country.key
20
20
  assert_equal 'England', rec.country.name
21
- # assert_equal true, rec.club
21
+ # assert_equal true, rec.clubs
22
22
 
23
23
  rec = League.search!( 'eng' )
24
- assert_equal 'Premier League', rec.title ## fix: add name alias (rename title to name!!)
24
+ assert_equal 'Premier League', rec.name
25
25
  assert_equal 'eng.1', rec.key
26
26
  assert_equal 'eng', rec.country.key
27
27
  assert_equal 'England', rec.country.name
28
- ## assert_equal true, rec.club
28
+ ## assert_equal true, rec.clubs
29
29
 
30
30
  ## try 2nd call (just lookup)
31
31
  rec = League.search_or_create!( 'eng' )
32
- assert_equal 'Premier League', rec.title ## fix: add name alias (rename title to name!!)
32
+ assert_equal 'Premier League', rec.name
33
33
  assert_equal 'eng.1', rec.key
34
34
  assert_equal 'eng', rec.country.key
35
35
  assert_equal 'England', rec.country.name
36
- ## assert_equal true, rec.club
36
+ ## assert_equal true, rec.clubs
37
37
  end
38
38
  end # class TestLeague
@@ -14,15 +14,15 @@ class TestMisc < MiniTest::Test
14
14
 
15
15
  def test_season
16
16
  rec = Season.search_or_create( '2017-18' )
17
- assert_equal '2017/18', rec.title ## fix: add name alias (rename title to name!!)
17
+ assert_equal '2017/18', rec.name
18
18
  assert_equal '2017/18', rec.key
19
19
 
20
20
  rec = Season.search_or_create( '2017/2018' )
21
- assert_equal '2017/18', rec.title ## fix: add name alias (rename title to name!!)
21
+ assert_equal '2017/18', rec.name
22
22
  assert_equal '2017/18', rec.key
23
23
 
24
24
  rec = Season.search_or_create( '2017/8' )
25
- assert_equal '2017/18', rec.title ## fix: add name alias (rename title to name!!)
25
+ assert_equal '2017/18', rec.name
26
26
  assert_equal '2017/18', rec.key
27
27
  end
28
28
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sportdb-sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-23 00:00:00.000000000 Z
11
+ date: 2020-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sportdb-config
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 1.19.0
33
+ version: 2.0.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 1.19.0
40
+ version: 2.0.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rdoc
43
43
  requirement: !ruby/object:Gem::Requirement