Class: SportDb::Sync::League

Inherits:
Object
  • Object
show all
Defined in:
lib/sportdb/readers/sync/league.rb

Class Method Summary collapse

Class Method Details

.find(league) ⇒ Object

finders



8
9
10
# File 'lib/sportdb/readers/sync/league.rb', line 8

def self.find( league )
  Model::League.find_by( key: league.key )
end

.find!(league) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/sportdb/readers/sync/league.rb', line 12

def self.find!( league )
  rec = find( league )
  if rec.nil?
    puts "** !!!ERROR!!! db sync - no league match found for:"
    pp league
    exit 1
  end
  rec
end

.find_or_create(league) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/sportdb/readers/sync/league.rb', line 22

def self.find_or_create( league )
  rec = find( league )
  if rec.nil?
     attribs = { key:   league.key,
                 name:  league.name }

    if league.country
       attribs[ :country_id ] = Sync::Country.find_or_create( league.country ).id
     end

     rec = Model::League.create!( attribs )
   end
   rec
end