Class: SportDb::Sync::Round

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

Class Method Summary collapse

Class Method Details

.find_or_create(round, event:) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/sportdb/sync/sync.rb', line 66

def self.find_or_create( round, event: )
   rec = Model::Round.find_by( name: round.name, event_id: event.id )
   if rec.nil?
     ## find last pos - check if it can be nil?
     max_pos = Model::Round.where( event_id: event.id ).maximum( 'pos' )
     max_pos = max_pos ? max_pos+1 : 1

     attribs = { event_id: event.id,
                 name:     round.name,
                 pos:      max_pos
               }

     ## todo/fix:  check if round has (optional) start or end date and add!!!
     ## attribs[ :start_date] = round.start_date.to_date

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