sportdb-sync 1.0.0 → 1.1.1
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 +4 -4
 - data/Rakefile +3 -3
 - data/lib/sportdb/sync.rb +2 -2
 - data/lib/sportdb/sync/club.rb +4 -4
 - data/lib/sportdb/sync/country.rb +2 -2
 - data/lib/sportdb/sync/event.rb +2 -2
 - data/lib/sportdb/sync/league.rb +1 -4
 - data/lib/sportdb/sync/season.rb +1 -1
 - data/lib/sportdb/sync/sync.rb +79 -30
 - data/lib/sportdb/sync/version.rb +4 -2
 - data/test/helper.rb +1 -1
 - data/test/test_country.rb +6 -6
 - data/test/test_league.rb +6 -6
 - data/test/test_misc.rb +3 -3
 - metadata +7 -7
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: e69405f0f6aab33c299ed7479747f1adb6e90282
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: ef45575530d5b0e899ff08f69089462486fd580a
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: f969dc99e13d4b5b98fddf63925e44f24e799cc5ae7d6ee8db34738e1140c9bbe8657199f389586a9ef6a16b895e39207f3e34e98b264c978934a853ee08800e
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 51a8e71e961fdd780561a038afe381026c5aca39838f210825b72f2aafc583bc85db62e5cf6190e32ec1256a983d410de26e1033b5ed9257020819e6894f4bd2
         
     | 
    
        data/Rakefile
    CHANGED
    
    | 
         @@ -3,7 +3,7 @@ require './lib/sportdb/sync/version.rb' 
     | 
|
| 
       3 
3 
     | 
    
         | 
| 
       4 
4 
     | 
    
         
             
            Hoe.spec 'sportdb-sync' do
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
              self.version = SportDb::Sync::VERSION
         
     | 
| 
      
 6 
     | 
    
         
            +
              self.version = SportDb::Module::Sync::VERSION
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
              self.summary = "sportdb-sync - sport.db sync helpers for leagues, seasons, clubs, match schedules and results, and more"
         
     | 
| 
       9 
9 
     | 
    
         
             
              self.description = summary
         
     | 
| 
         @@ -20,8 +20,8 @@ Hoe.spec 'sportdb-sync' do 
     | 
|
| 
       20 
20 
     | 
    
         
             
              self.licenses = ['Public Domain']
         
     | 
| 
       21 
21 
     | 
    
         | 
| 
       22 
22 
     | 
    
         
             
              self.extra_deps = [
         
     | 
| 
       23 
     | 
    
         
            -
                ['sportdb- 
     | 
| 
       24 
     | 
    
         
            -
                ['sportdb-models', 
     | 
| 
      
 23 
     | 
    
         
            +
                ['sportdb-catalogs',  '>= 1.0.0'],
         
     | 
| 
      
 24 
     | 
    
         
            +
                ['sportdb-models',    '>= 2.0.2'],
         
     | 
| 
       25 
25 
     | 
    
         
             
              ]
         
     | 
| 
       26 
26 
     | 
    
         | 
| 
       27 
27 
     | 
    
         
             
              self.spec_extras = {
         
     | 
    
        data/lib/sportdb/sync.rb
    CHANGED
    
    | 
         @@ -1,6 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # encoding: utf-8
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            require 'sportdb/ 
     | 
| 
      
 3 
     | 
    
         
            +
            require 'sportdb/catalogs'
         
     | 
| 
       4 
4 
     | 
    
         
             
            require 'sportdb/models'   ## add sql database support
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         | 
| 
         @@ -16,4 +16,4 @@ require 'sportdb/sync/club' 
     | 
|
| 
       16 
16 
     | 
    
         
             
            require 'sportdb/sync/sync'
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
            puts SportDb::Sync.banner   # say hello
         
     | 
| 
      
 19 
     | 
    
         
            +
            puts SportDb::Module::Sync.banner   # say hello
         
     | 
    
        data/lib/sportdb/sync/club.rb
    CHANGED
    
    | 
         @@ -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 
     | 
| 
       54 
     | 
    
         
            -
                    rec = Model::Team.find_by(  
     | 
| 
      
 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 
     | 
    
         
            -
                           
     | 
| 
      
 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[: 
     | 
| 
      
 74 
     | 
    
         
            +
                        attribs[:alt_names] = club.alt_names.join('|')
         
     | 
| 
       75 
75 
     | 
    
         
             
                      end
         
     | 
| 
       76 
76 
     | 
    
         | 
| 
       77 
77 
     | 
    
         
             
                      rec = Model::Team.create!( attribs )
         
     | 
    
        data/lib/sportdb/sync/country.rb
    CHANGED
    
    | 
         @@ -57,8 +57,8 @@ module SportDb 
     | 
|
| 
       57 
57 
     | 
    
         
             
                    attribs = {
         
     | 
| 
       58 
58 
     | 
    
         
             
                      key:  country.key,
         
     | 
| 
       59 
59 
     | 
    
         
             
                      name: country.name,
         
     | 
| 
       60 
     | 
    
         
            -
                      code: country. 
     | 
| 
       61 
     | 
    
         
            -
                      fifa: country.fifa,
         
     | 
| 
      
 60 
     | 
    
         
            +
                      code: country.code,  ## fix:  uses fifa code now (should be iso-alpha3 if available)
         
     | 
| 
      
 61 
     | 
    
         
            +
                      ## fifa: country.fifa,
         
     | 
| 
       62 
62 
     | 
    
         
             
                      area: 1,
         
     | 
| 
       63 
63 
     | 
    
         
             
                      pop:  1
         
     | 
| 
       64 
64 
     | 
    
         
             
                    }
         
     | 
    
        data/lib/sportdb/sync/event.rb
    CHANGED
    
    | 
         @@ -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"  
     | 
| 
       83 
     | 
    
         
            -
                      attribs[: 
     | 
| 
      
 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 )
         
     | 
    
        data/lib/sportdb/sync/league.rb
    CHANGED
    
    | 
         @@ -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 
     | 
    
         
            -
                                  
     | 
| 
      
 44 
     | 
    
         
            +
                                 name:  league.name }
         
     | 
| 
       48 
45 
     | 
    
         | 
| 
       49 
46 
     | 
    
         
             
                    if league.country
         
     | 
| 
       50 
47 
     | 
    
         
             
                       attribs[ :country_id ] = Sync::Country.find_or_create( league.country ).id
         
     | 
    
        data/lib/sportdb/sync/season.rb
    CHANGED
    
    
    
        data/lib/sportdb/sync/sync.rb
    CHANGED
    
    | 
         @@ -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(  
     | 
| 
      
 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 
     | 
    
         
            -
                       
     | 
| 
      
 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[: 
     | 
| 
      
 24 
     | 
    
         
            +
                      attribs[:alt_names] = team.alt_names.join('|')
         
     | 
| 
       25 
25 
     | 
    
         
             
                    end
         
     | 
| 
       26 
26 
     | 
    
         | 
| 
       27 
27 
     | 
    
         
             
                    rec = Model::Team.create!( attribs )
         
     | 
| 
         @@ -64,13 +64,20 @@ module SportDb 
     | 
|
| 
       64 
64 
     | 
    
         | 
| 
       65 
65 
     | 
    
         
             
              class Round
         
     | 
| 
       66 
66 
     | 
    
         
             
                def self.find_or_create( round, event: )
         
     | 
| 
       67 
     | 
    
         
            -
                   rec = Model::Round.find_by(  
     | 
| 
      
 67 
     | 
    
         
            +
                   rec = Model::Round.find_by( name: round.name, event_id: event.id )
         
     | 
| 
       68 
68 
     | 
    
         
             
                   if rec.nil?
         
     | 
| 
      
 69 
     | 
    
         
            +
                     ## find last pos - check if it can be nil?
         
     | 
| 
      
 70 
     | 
    
         
            +
                     max_pos = Model::Round.where( event_id: event.id ).maximum( 'pos' )
         
     | 
| 
      
 71 
     | 
    
         
            +
                     max_pos = max_pos ? max_pos+1 : 1
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
       69 
73 
     | 
    
         
             
                     attribs = { event_id: event.id,
         
     | 
| 
       70 
     | 
    
         
            -
                                  
     | 
| 
       71 
     | 
    
         
            -
                                 pos:       
     | 
| 
       72 
     | 
    
         
            -
                                 start_at: event.start_at.to_date
         
     | 
| 
      
 74 
     | 
    
         
            +
                                 name:     round.name,
         
     | 
| 
      
 75 
     | 
    
         
            +
                                 pos:      max_pos
         
     | 
| 
       73 
76 
     | 
    
         
             
                               }
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
                     ## todo/fix:  check if round has (optional) start or end date and add!!!
         
     | 
| 
      
 79 
     | 
    
         
            +
                     ## attribs[ :start_date] = round.start_date.to_date
         
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
       74 
81 
     | 
    
         
             
                     rec = Model::Round.create!( attribs )
         
     | 
| 
       75 
82 
     | 
    
         
             
                   end
         
     | 
| 
       76 
83 
     | 
    
         
             
                   rec
         
     | 
| 
         @@ -80,12 +87,18 @@ module SportDb 
     | 
|
| 
       80 
87 
     | 
    
         | 
| 
       81 
88 
     | 
    
         
             
              class Group
         
     | 
| 
       82 
89 
     | 
    
         
             
                def self.find_or_create( group, event: )
         
     | 
| 
       83 
     | 
    
         
            -
                   rec = Model::Group.find_by(  
     | 
| 
      
 90 
     | 
    
         
            +
                   rec = Model::Group.find_by( name: group.name, event_id: event.id )
         
     | 
| 
       84 
91 
     | 
    
         
             
                   if rec.nil?
         
     | 
| 
      
 92 
     | 
    
         
            +
                     ## find last pos - check if it can be nil?
         
     | 
| 
      
 93 
     | 
    
         
            +
                     max_pos = Model::Group.where( event_id: event.id ).maximum( 'pos' )
         
     | 
| 
      
 94 
     | 
    
         
            +
                     max_pos = max_pos ? max_pos+1 : 1
         
     | 
| 
      
 95 
     | 
    
         
            +
             
     | 
| 
       85 
96 
     | 
    
         
             
                     attribs = { event_id: event.id,
         
     | 
| 
       86 
     | 
    
         
            -
                                  
     | 
| 
       87 
     | 
    
         
            -
                                 pos:       
     | 
| 
      
 97 
     | 
    
         
            +
                                 name:     group.name,
         
     | 
| 
      
 98 
     | 
    
         
            +
                                 pos:      max_pos
         
     | 
| 
       88 
99 
     | 
    
         
             
                               }
         
     | 
| 
      
 100 
     | 
    
         
            +
             
     | 
| 
      
 101 
     | 
    
         
            +
                     ## todo/fix: check/add optional group key (was: pos before)!!!!
         
     | 
| 
       89 
102 
     | 
    
         
             
                     rec = Model::Group.create!( attribs )
         
     | 
| 
       90 
103 
     | 
    
         
             
                   end
         
     | 
| 
       91 
104 
     | 
    
         
             
                   ## todo/fix: add/update teams in group too!!!!!
         
     | 
| 
         @@ -96,7 +109,7 @@ module SportDb 
     | 
|
| 
       96 
109 
     | 
    
         | 
| 
       97 
110 
     | 
    
         
             
              class Stage
         
     | 
| 
       98 
111 
     | 
    
         
             
                def self.find( name, event: )
         
     | 
| 
       99 
     | 
    
         
            -
                  Model::Stage.find_by(  
     | 
| 
      
 112 
     | 
    
         
            +
                  Model::Stage.find_by( name: name, event_id: event.id  )
         
     | 
| 
       100 
113 
     | 
    
         
             
                end
         
     | 
| 
       101 
114 
     | 
    
         
             
                def self.find!( name, event: )
         
     | 
| 
       102 
115 
     | 
    
         
             
                  rec = find( name, event: event  )
         
     | 
| 
         @@ -112,10 +125,8 @@ module SportDb 
     | 
|
| 
       112 
125 
     | 
    
         
             
                def self.find_or_create( name, event: )
         
     | 
| 
       113 
126 
     | 
    
         
             
                   rec = find( name, event: event )
         
     | 
| 
       114 
127 
     | 
    
         
             
                   if rec.nil?
         
     | 
| 
       115 
     | 
    
         
            -
                     ## use title and not name - why? why not?
         
     | 
| 
       116 
     | 
    
         
            -
                     ##  quick fix:  change name to title
         
     | 
| 
       117 
128 
     | 
    
         
             
                     attribs = { event_id: event.id,
         
     | 
| 
       118 
     | 
    
         
            -
                                  
     | 
| 
      
 129 
     | 
    
         
            +
                                 name:     name,
         
     | 
| 
       119 
130 
     | 
    
         
             
                               }
         
     | 
| 
       120 
131 
     | 
    
         
             
                     rec = Model::Stage.create!( attribs )
         
     | 
| 
       121 
132 
     | 
    
         
             
                   end
         
     | 
| 
         @@ -125,21 +136,28 @@ module SportDb 
     | 
|
| 
       125 
136 
     | 
    
         | 
| 
       126 
137 
     | 
    
         | 
| 
       127 
138 
     | 
    
         | 
| 
       128 
     | 
    
         
            -
              class Match 
     | 
| 
      
 139 
     | 
    
         
            +
              class Match
         
     | 
| 
      
 140 
     | 
    
         
            +
                ### todo/fix: rename to create!!   (add update support later) !!!!
         
     | 
| 
      
 141 
     | 
    
         
            +
                ##    use update_by_round  or update_by_date or update_by_teams or such
         
     | 
| 
      
 142 
     | 
    
         
            +
                ##      NO easy (unique always auto-id match) possible!!!!!!
         
     | 
| 
       129 
143 
     | 
    
         
             
                def self.create_or_update( match, event: )
         
     | 
| 
       130 
144 
     | 
    
         
             
                   ## note: MUST find round, thus, use bang (!)
         
     | 
| 
       131 
145 
     | 
    
         | 
| 
       132 
146 
     | 
    
         
             
                   ## todo/check: allow strings too - why? why not?
         
     | 
| 
       133 
147 
     | 
    
         | 
| 
       134 
     | 
    
         
            -
                    
     | 
| 
       135 
     | 
    
         
            -
             
     | 
| 
       136 
     | 
    
         
            -
             
     | 
| 
       137 
     | 
    
         
            -
             
     | 
| 
      
 148 
     | 
    
         
            +
                   round_rec = if match.round
         
     | 
| 
      
 149 
     | 
    
         
            +
                                 ## query for round - allow string or round rec
         
     | 
| 
      
 150 
     | 
    
         
            +
                                 round_name  = match.round.is_a?( String ) ? match.round : match.round.name
         
     | 
| 
      
 151 
     | 
    
         
            +
                                 Model::Round.find_by!( event_id: event.id,
         
     | 
| 
      
 152 
     | 
    
         
            +
                                                        name:     round_name )
         
     | 
| 
      
 153 
     | 
    
         
            +
                               else    # note: allow matches WITHOUT rounds too (e.g. England Football League 1888 and others)
         
     | 
| 
      
 154 
     | 
    
         
            +
                                 nil
         
     | 
| 
      
 155 
     | 
    
         
            +
                               end
         
     | 
| 
       138 
156 
     | 
    
         | 
| 
       139 
157 
     | 
    
         
             
                   ## todo/check: allow fallback with db lookup if NOT found in cache - why? why not?
         
     | 
| 
       140 
158 
     | 
    
         
             
                   ##  or better use Sync::Team.find_or_create( team )  !!!!!!! to auto-create on first hit!
         
     | 
| 
       141 
159 
     | 
    
         
             
                   ##    || Team.find_or_create( team1 )  -- note: does NOT work for string (only recs) - what to do?
         
     | 
| 
       142 
     | 
    
         
            -
                   ##    || Model::Team.find_by!(  
     | 
| 
      
 160 
     | 
    
         
            +
                   ##    || Model::Team.find_by!( name: team1_name )
         
     | 
| 
       143 
161 
     | 
    
         
             
                   team1_name   = match.team1.is_a?( String ) ? match.team1 : match.team1.name
         
     | 
| 
       144 
162 
     | 
    
         
             
                   team1_rec    = Team.cache[ team1_name ]
         
     | 
| 
       145 
163 
     | 
    
         
             
                   team2_name   = match.team2.is_a?( String ) ? match.team2 : match.team2.name
         
     | 
| 
         @@ -147,32 +165,63 @@ module SportDb 
     | 
|
| 
       147 
165 
     | 
    
         | 
| 
       148 
166 
     | 
    
         
             
                   ## check optional group (e.g. Group A, etc.)
         
     | 
| 
       149 
167 
     | 
    
         
             
                   group_rec = if match.group
         
     | 
| 
       150 
     | 
    
         
            -
                                  
     | 
| 
      
 168 
     | 
    
         
            +
                                 group_name = match.group.is_a?( String ) ? match.group : match.group.name
         
     | 
| 
       151 
169 
     | 
    
         
             
                                 Model::Group.find_by!( event_id: event.id,
         
     | 
| 
       152 
     | 
    
         
            -
                                                         
     | 
| 
      
 170 
     | 
    
         
            +
                                                        name:     group_name )
         
     | 
| 
       153 
171 
     | 
    
         
             
                               else
         
     | 
| 
       154 
172 
     | 
    
         
             
                                 nil
         
     | 
| 
       155 
173 
     | 
    
         
             
                               end
         
     | 
| 
       156 
174 
     | 
    
         | 
| 
      
 175 
     | 
    
         
            +
                   ## check optional stage (e.g. Regular, Play Off, Relegation, etc. )
         
     | 
| 
      
 176 
     | 
    
         
            +
                   stage_rec = if match.stage
         
     | 
| 
      
 177 
     | 
    
         
            +
                                 stage_name = match.stage.is_a?( String ) ? match.stage : match.stage.name
         
     | 
| 
      
 178 
     | 
    
         
            +
                                 Model::Stage.find_by!( event_id: event.id,
         
     | 
| 
      
 179 
     | 
    
         
            +
                                                        name:     stage_name )
         
     | 
| 
      
 180 
     | 
    
         
            +
                               else
         
     | 
| 
      
 181 
     | 
    
         
            +
                                 nil
         
     | 
| 
      
 182 
     | 
    
         
            +
                               end
         
     | 
| 
      
 183 
     | 
    
         
            +
             
     | 
| 
      
 184 
     | 
    
         
            +
                   ### todo/check: what happens if there's more than one match? exception raised??
         
     | 
| 
      
 185 
     | 
    
         
            +
                   rec = if round_rec
         
     | 
| 
      
 186 
     | 
    
         
            +
                           ## add match status too? allows [abandoned] and [replay] in same round
         
     | 
| 
      
 187 
     | 
    
         
            +
                           Model::Match.find_by( round_id: round_rec.id,
         
     | 
| 
      
 188 
     | 
    
         
            +
                                                 team1_id: team1_rec.id,
         
     | 
| 
      
 189 
     | 
    
         
            +
                                                 team2_id: team2_rec.id )
         
     | 
| 
      
 190 
     | 
    
         
            +
                         else
         
     | 
| 
      
 191 
     | 
    
         
            +
                           ## always assume new record for now
         
     | 
| 
      
 192 
     | 
    
         
            +
                           ##   check for date or such - why? why not?
         
     | 
| 
      
 193 
     | 
    
         
            +
                           nil
         
     | 
| 
      
 194 
     | 
    
         
            +
                         end
         
     | 
| 
       157 
195 
     | 
    
         | 
| 
       158 
     | 
    
         
            -
                   rec = Model::Game.find_by( round_id: round_rec.id,
         
     | 
| 
       159 
     | 
    
         
            -
                                              team1_id: team1_rec.id,
         
     | 
| 
       160 
     | 
    
         
            -
                                              team2_id: team2_rec.id )
         
     | 
| 
       161 
196 
     | 
    
         
             
                   if rec.nil?
         
     | 
| 
       162 
     | 
    
         
            -
             
     | 
| 
      
 197 
     | 
    
         
            +
                    ## find last pos - check if it can be nil?  yes, is nil if no records found
         
     | 
| 
      
 198 
     | 
    
         
            +
                     max_pos = Model::Match.where( event_id: event.id ).maximum( 'pos' )
         
     | 
| 
      
 199 
     | 
    
         
            +
                     max_pos = max_pos ? max_pos+1 : 1
         
     | 
| 
      
 200 
     | 
    
         
            +
             
     | 
| 
      
 201 
     | 
    
         
            +
                     attribs = { event_id: event.id,          ## todo/fix: change to data struct too?
         
     | 
| 
       163 
202 
     | 
    
         
             
                                 team1_id: team1_rec.id,
         
     | 
| 
       164 
203 
     | 
    
         
             
                                 team2_id: team2_rec.id,
         
     | 
| 
       165 
     | 
    
         
            -
                                 pos:       
     | 
| 
       166 
     | 
    
         
            -
                                  
     | 
| 
      
 204 
     | 
    
         
            +
                                 pos:      max_pos,
         
     | 
| 
      
 205 
     | 
    
         
            +
                                 date:     match.date.to_date,  ## todo/fix: split and add date & time!!!!
         
     | 
| 
       167 
206 
     | 
    
         
             
                                 score1:   match.score1,
         
     | 
| 
       168 
207 
     | 
    
         
             
                                 score2:   match.score2,
         
     | 
| 
       169 
208 
     | 
    
         
             
                                 score1i:  match.score1i,
         
     | 
| 
       170 
     | 
    
         
            -
                                 score2i:  match.score2i 
     | 
| 
      
 209 
     | 
    
         
            +
                                 score2i:  match.score2i,
         
     | 
| 
      
 210 
     | 
    
         
            +
                                 score1et: match.score1et,
         
     | 
| 
      
 211 
     | 
    
         
            +
                                 score2et: match.score2et,
         
     | 
| 
      
 212 
     | 
    
         
            +
                                 score1p:  match.score1p,
         
     | 
| 
      
 213 
     | 
    
         
            +
                                 score2p:  match.score2p,
         
     | 
| 
      
 214 
     | 
    
         
            +
                                 status:   match.status }
         
     | 
| 
      
 215 
     | 
    
         
            +
             
     | 
| 
      
 216 
     | 
    
         
            +
                     attribs[ :round_id ] = round_rec.id   if round_rec
         
     | 
| 
       171 
217 
     | 
    
         
             
                     attribs[ :group_id ] = group_rec.id   if group_rec
         
     | 
| 
      
 218 
     | 
    
         
            +
                     attribs[ :stage_id ] = stage_rec.id   if stage_rec
         
     | 
| 
       172 
219 
     | 
    
         | 
| 
       173 
     | 
    
         
            -
                     rec = Model:: 
     | 
| 
      
 220 
     | 
    
         
            +
                     rec = Model::Match.create!( attribs )
         
     | 
| 
       174 
221 
     | 
    
         
             
                   else
         
     | 
| 
       175 
222 
     | 
    
         
             
                     # update - todo
         
     | 
| 
      
 223 
     | 
    
         
            +
                     puts "!! ERROR - match updates not yet supported (only inserts); sorry"
         
     | 
| 
      
 224 
     | 
    
         
            +
                     exit 1
         
     | 
| 
       176 
225 
     | 
    
         
             
                   end
         
     | 
| 
       177 
226 
     | 
    
         
             
                   rec
         
     | 
| 
       178 
227 
     | 
    
         
             
                end
         
     | 
    
        data/lib/sportdb/sync/version.rb
    CHANGED
    
    | 
         @@ -2,11 +2,12 @@ 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
4 
     | 
    
         
             
            module SportDb
         
     | 
| 
      
 5 
     | 
    
         
            +
            module Module
         
     | 
| 
       5 
6 
     | 
    
         
             
            module Sync
         
     | 
| 
       6 
7 
     | 
    
         | 
| 
       7 
8 
     | 
    
         
             
              MAJOR = 1    ## todo: namespace inside version or something - why? why not??
         
     | 
| 
       8 
     | 
    
         
            -
              MINOR =  
     | 
| 
       9 
     | 
    
         
            -
              PATCH =  
     | 
| 
      
 9 
     | 
    
         
            +
              MINOR = 1
         
     | 
| 
      
 10 
     | 
    
         
            +
              PATCH = 1
         
     | 
| 
       10 
11 
     | 
    
         
             
              VERSION = [MAJOR,MINOR,PATCH].join('.')
         
     | 
| 
       11 
12 
     | 
    
         | 
| 
       12 
13 
     | 
    
         
             
              def self.version
         
     | 
| 
         @@ -22,4 +23,5 @@ module Sync 
     | 
|
| 
       22 
23 
     | 
    
         
             
              end
         
     | 
| 
       23 
24 
     | 
    
         | 
| 
       24 
25 
     | 
    
         
             
            end # module Sync
         
     | 
| 
      
 26 
     | 
    
         
            +
            end # module Module
         
     | 
| 
       25 
27 
     | 
    
         
             
            end # module SportDb
         
     | 
    
        data/test/helper.rb
    CHANGED
    
    | 
         @@ -1,6 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ## note: use the local version of sportdb gems
         
     | 
| 
       2 
2 
     | 
    
         
             
            $LOAD_PATH.unshift( File.expand_path( '../sportdb-formats/lib' ))
         
     | 
| 
       3 
     | 
    
         
            -
            $LOAD_PATH.unshift( File.expand_path( '../sportdb- 
     | 
| 
      
 3 
     | 
    
         
            +
            $LOAD_PATH.unshift( File.expand_path( '../sportdb-catalogs/lib' ))
         
     | 
| 
       4 
4 
     | 
    
         
             
            $LOAD_PATH.unshift( File.expand_path( '../sportdb-models/lib' ))
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         | 
    
        data/test/test_country.rb
    CHANGED
    
    | 
         @@ -13,8 +13,8 @@ class TestCountry < MiniTest::Test 
     | 
|
| 
       13 
13 
     | 
    
         
             
              Country = SportDb::Sync::Country
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
       15 
15 
     | 
    
         
             
              def test_find  # note: find uses "data" structs
         
     | 
| 
       16 
     | 
    
         
            -
                at  = SportDb::Import::Country.new( key: 'at',  name: 'Austria',  
     | 
| 
       17 
     | 
    
         
            -
                eng = SportDb::Import::Country.new( key: 'eng', name: 'England',  
     | 
| 
      
 16 
     | 
    
         
            +
                at  = SportDb::Import::Country.new( key: 'at',  name: 'Austria', code: 'AUT' )
         
     | 
| 
      
 17 
     | 
    
         
            +
                eng = SportDb::Import::Country.new( key: 'eng', name: 'England', code: 'ENG' )
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
19 
     | 
    
         
             
                rec  = Country.find_or_create( at )
         
     | 
| 
       20 
20 
     | 
    
         
             
                rec2 = Country.find_or_create( at )
         
     | 
| 
         @@ -28,23 +28,23 @@ class TestCountry < MiniTest::Test 
     | 
|
| 
       28 
28 
     | 
    
         
             
                rec = Country.search_or_create!( 'at' )  ## try (iso-alpha2) key
         
     | 
| 
       29 
29 
     | 
    
         
             
                assert_equal 'Austria', rec.name
         
     | 
| 
       30 
30 
     | 
    
         
             
                assert_equal 'at',      rec.key
         
     | 
| 
       31 
     | 
    
         
            -
                assert_equal 'AUT',     rec. 
     | 
| 
      
 31 
     | 
    
         
            +
                assert_equal 'AUT',     rec.code
         
     | 
| 
       32 
32 
     | 
    
         | 
| 
       33 
33 
     | 
    
         
             
                rec = Country.search_or_create!( 'aut' )  ## try fifa code
         
     | 
| 
       34 
34 
     | 
    
         
             
                assert_equal 'Austria', rec.name
         
     | 
| 
       35 
35 
     | 
    
         
             
                assert_equal 'at',      rec.key
         
     | 
| 
       36 
     | 
    
         
            -
                assert_equal 'AUT',     rec. 
     | 
| 
      
 36 
     | 
    
         
            +
                assert_equal 'AUT',     rec.code
         
     | 
| 
       37 
37 
     | 
    
         | 
| 
       38 
38 
     | 
    
         | 
| 
       39 
39 
     | 
    
         
             
                rec = Country.search_or_create!( 'eng' )
         
     | 
| 
       40 
40 
     | 
    
         
             
                assert_equal 'England', rec.name
         
     | 
| 
       41 
41 
     | 
    
         
             
                assert_equal 'eng',     rec.key
         
     | 
| 
       42 
     | 
    
         
            -
                assert_equal 'ENG',     rec. 
     | 
| 
      
 42 
     | 
    
         
            +
                assert_equal 'ENG',     rec.code
         
     | 
| 
       43 
43 
     | 
    
         | 
| 
       44 
44 
     | 
    
         
             
                rec = Country.search_or_create!( 'eng' )
         
     | 
| 
       45 
45 
     | 
    
         
             
                assert_equal 'England', rec.name
         
     | 
| 
       46 
46 
     | 
    
         
             
                assert_equal 'eng',     rec.key
         
     | 
| 
       47 
     | 
    
         
            -
                assert_equal 'ENG',     rec. 
     | 
| 
      
 47 
     | 
    
         
            +
                assert_equal 'ENG',     rec.code
         
     | 
| 
       48 
48 
     | 
    
         
             
              end
         
     | 
| 
       49 
49 
     | 
    
         | 
| 
       50 
50 
     | 
    
         
             
            end  # class TestCountry
         
     | 
    
        data/test/test_league.rb
    CHANGED
    
    | 
         @@ -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. 
     | 
| 
      
 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. 
     | 
| 
      
 21 
     | 
    
         
            +
                # assert_equal true,              rec.clubs
         
     | 
| 
       22 
22 
     | 
    
         | 
| 
       23 
23 
     | 
    
         
             
                rec = League.search!( 'eng' )
         
     | 
| 
       24 
     | 
    
         
            -
                assert_equal 'Premier League',  rec. 
     | 
| 
      
 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. 
     | 
| 
      
 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. 
     | 
| 
      
 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. 
     | 
| 
      
 36 
     | 
    
         
            +
                ## assert_equal true,                 rec.clubs
         
     | 
| 
       37 
37 
     | 
    
         
             
              end
         
     | 
| 
       38 
38 
     | 
    
         
             
            end # class TestLeague
         
     | 
    
        data/test/test_misc.rb
    CHANGED
    
    | 
         @@ -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. 
     | 
| 
      
 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. 
     | 
| 
      
 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. 
     | 
| 
      
 25 
     | 
    
         
            +
                assert_equal '2017/18', rec.name
         
     | 
| 
       26 
26 
     | 
    
         
             
                assert_equal '2017/18', rec.key
         
     | 
| 
       27 
27 
     | 
    
         
             
              end
         
     | 
| 
       28 
28 
     | 
    
         | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,43 +1,43 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: sportdb-sync
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.1.1
         
     | 
| 
       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- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2020-08-01 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
     | 
    
         
            -
              name: sportdb- 
     | 
| 
      
 14 
     | 
    
         
            +
              name: sportdb-catalogs
         
     | 
| 
       15 
15 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
       16 
16 
     | 
    
         
             
                requirements:
         
     | 
| 
       17 
17 
     | 
    
         
             
                - - ">="
         
     | 
| 
       18 
18 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       19 
     | 
    
         
            -
                    version: 1.0. 
     | 
| 
      
 19 
     | 
    
         
            +
                    version: 1.0.0
         
     | 
| 
       20 
20 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       21 
21 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       22 
22 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       23 
23 
     | 
    
         
             
                requirements:
         
     | 
| 
       24 
24 
     | 
    
         
             
                - - ">="
         
     | 
| 
       25 
25 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       26 
     | 
    
         
            -
                    version: 1.0. 
     | 
| 
      
 26 
     | 
    
         
            +
                    version: 1.0.0
         
     | 
| 
       27 
27 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       28 
28 
     | 
    
         
             
              name: sportdb-models
         
     | 
| 
       29 
29 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
       30 
30 
     | 
    
         
             
                requirements:
         
     | 
| 
       31 
31 
     | 
    
         
             
                - - ">="
         
     | 
| 
       32 
32 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       33 
     | 
    
         
            -
                    version:  
     | 
| 
      
 33 
     | 
    
         
            +
                    version: 2.0.2
         
     | 
| 
       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:  
     | 
| 
      
 40 
     | 
    
         
            +
                    version: 2.0.2
         
     | 
| 
       41 
41 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       42 
42 
     | 
    
         
             
              name: rdoc
         
     | 
| 
       43 
43 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     |