Class: SportDb::Sync::League

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

Class Method Summary collapse

Class Method Details

.find(league) ⇒ Object

finders



26
27
28
# File 'lib/sportdb/sync/league.rb', line 26

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

.find!(league) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/sportdb/sync/league.rb', line 30

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



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/sportdb/sync/league.rb', line 40

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

.league(q) ⇒ Object

todo/check: find a better or “generic” alias name e.g. convert/builtin/etc. - why? why not?



5
6
7
# File 'lib/sportdb/sync/league.rb', line 5

def self.league( q )   ## todo/check: find a better or "generic" alias name e.g. convert/builtin/etc. - why? why not?
  Import.catalog.leagues.find!( q )     ## todo/fix: change find to search!!!
end

.search!(q) ⇒ Object

searchers



13
14
15
16
# File 'lib/sportdb/sync/league.rb', line 13

def self.search!( q )   ## note: use search for passing in string queries (and find for records/structs only)
  league = league( q )
  find( league )
end

.search_or_create!(q) ⇒ Object



18
19
20
21
# File 'lib/sportdb/sync/league.rb', line 18

def self.search_or_create!( q )
  league = league( q )
  find_or_create( league )
end