Class: SportDb::Sync::Round

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

Class Method Summary collapse

Class Method Details

.find_or_create(round, event:) ⇒ Object



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

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