app/strategies/relay_swimmer_updater.rb
# Process a single MeetingRelaySwimmer, keyed by a instance of MeetingRelayResult
# and the relay order.
#
# The row will be:
# - updated, when the row exists; (must provide a valid swimmer_id)
# - created with the specified values, when not found; (must provide a valid swimmer_id)
# - deleted, when the swimmer_id specified is nil and the row itself is existing.
#
# The method will act according to the presence of the first 3 parameters,
# the others are not required and can be nil.
# The method updates also the internal SQL diff log file accordingly.
#
# == Returns:
#
# The updated/created MeetingRelaySwimmer resulting instance,
# or +true+ in case of deletion;
#
# Result is +false+ when the row was not found and the deletion was skipped,
# or +nil+ only in case of error during the update/create transaction.
#
Process a single MeetingRelaySwimmer, keyed by a instance of MeetingRelayResult
and the relay order.

The row will be:
updated, when the row exists; (must provide a valid swimmer_id)
created with the specified values, when not found; (must provide a valid swimmer_id)
deleted, when the swimmer_id specified is nil and the row itself is existing.

The method will act according to the presence of the first 3 parameters,
the others are not required and can be nil.
The method updates also the internal SQL diff log file accordingly.



The updated/created MeetingRelaySwimmer resulting instance,
or +true+ in case of deletion.

Result is +false+ when the row was not found and the deletion was skipped,
or +nil+ only in case of error during the update/create transaction.
Process a single MeetingRelaySwimmer keyed by a instance of MeetingRelayResult and the relay order . The row will be : updated when the row exists ; ( must provide a valid swimmer_id ) created with the specified values when not found ; ( must provide a valid swimmer_id ) deleted when the swimmer_id specified is nil and the row itself is existing . The method will act according to the presence of the first 3 parameters the others are not required and can be nil . The method updates also the internal SQL diff log file accordingly . The updated / created MeetingRelaySwimmer resulting instance or + true + in case of deletion . Result is + false + when the row was not found and the deletion was skipped or + nil + only in case of error during the update / create transaction .
def process!( mrr, relay_order, swimmer_id, incremental_timing_text_value, reaction_time_text )
    return nil unless mrr.instance_of?( MeetingRelayResult ) && (relay_order.to_i > 0)
    mrs = MeetingRelaySwimmer.where( meeting_relay_result_id: mrr.id, relay_order: relay_order ).first
    return false if mrs.nil? && (swimmer_id.to_i < 1) && (!incremental_timing_text_value.present?) && (!reaction_time_text.present?)
    if mrs && swimmer_id.to_i < 1                   
      return delete_existing_row!( mrs )
    else                                            
      team_id   = mrr.team_id
      season_id = mrr.season.id
      badge     = Badge.where( team_id: team_id, season_id: season_id, swimmer_id: swimmer_id ).first
      stroke_type_id = RelaySwimmerUpdater.get_fractionist_stroke_type_id_by( mrr.event_type.stroke_type_id, relay_order )
      unless badge && stroke_type_id
        return nil
      end
      timing = TimingParser.parse( incremental_timing_text_value )
      reaction_time = TimingParser.parse( reaction_time_text ) if reaction_time_text
      MeetingRelaySwimmer.transaction do
        if mrs                                    
          edit_existing_row!( mrs, swimmer_id, badge.id, stroke_type_id, timing, reaction_time )
        else                                      
          create_new_row!( mrr, relay_order, swimmer_id, badge.id, stroke_type_id, timing, reaction_time )
        end
      end
    end
  rescue
    puts "RESCUE: '#{ $! }'"
    puts caller
    return nil
  end
def process! ( mrr , relay_order , swimmer_id , incremental_timing_text_value , reaction_time_text ) return nil unless mrr . instance_of? ( MeetingRelayResult ) && ( relay_order . to_i > 0 ) mrs = MeetingRelaySwimmer . where ( meeting_relay_result_id : mrr . id , relay_order : relay_order ) . first return false if mrs . nil? && ( swimmer_id . to_i < 1 ) && ( ! incremental_timing_text_value . present? ) && ( ! reaction_time_text . present? ) if mrs && swimmer_id . to_i < 1 return delete_existing_row! ( mrs ) else team_id = mrr . team_id season_id = mrr . season . id badge = Badge . where ( team_id : team_id , season_id : season_id , swimmer_id : swimmer_id ) . first stroke_type_id = RelaySwimmerUpdater . get_fractionist_stroke_type_id_by ( mrr . event_type . stroke_type_id , relay_order ) unless badge && stroke_type_id return nil end timing = TimingParser . parse ( incremental_timing_text_value ) reaction_time = TimingParser . parse ( reaction_time_text ) if reaction_time_text MeetingRelaySwimmer . transaction do if mrs edit_existing_row! ( mrs , swimmer_id , badge . id , stroke_type_id , timing , reaction_time ) else create_new_row! ( mrr , relay_order , swimmer_id , badge . id , stroke_type_id , timing , reaction_time ) end end end rescue puts "RESCUE: '#{ $! }'" puts caller return nil end
Process a single MeetingRelaySwimmer, keyed by a instance of MeetingRelayResult
and the relay order.
Process a single MeetingRelaySwimmer keyed by a instance of MeetingRelayResult and the relay order .
# Nothing to do, bail out: # --- DELETE --- # --- UPDATE or CREATE (Assuming swimmer_id is provided) --- # DEBUG #      puts "MRR #{ mrr.id }. Seeking badge for team: #{ team_id }, season: #{ season_id }, swimmer: #{ swimmer_id }" # DEBUG #        puts "badge (#{ badge ? badge.id : 'nil'}) or stroke_type_id (#{ stroke_type_id }) NOT found" # DEBUG #      puts "timing: '#{ incremental_timing_text_value }' => #{ timing }\r\nreaction: '#{ reaction_time_text }' => #{ reaction_time }" # --- UPDATE --- # DEBUG #          puts "before UPDATE" # --- CREATE --- # DEBUG #          puts "before CREATE" # DEBUG
mrr
<not_specific>
relay_order
<not_specific>
swimmer_id
<not_specific>
incremental_timing_text_value
<not_specific>
reaction_time_text
<not_specific>