All checks were successful
		
		
	
	Check usage of free licenses / check-licenses (pull_request) Successful in 1m38s
				
			Add copyright notice / copyright_notice (pull_request) Successful in 3m16s
				
			Run unit tests / unit_tests (pull_request) Successful in 5m31s
				
			Build Nginx-based docker image / build-static-assets (pull_request) Successful in 41m31s
				
			
		
			
				
	
	
		
			44 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
| # Copyright (C) 2024-2025 LibreWeddingPlanner contributors
 | |
| 
 | |
| # frozen_string_literal: true
 | |
| 
 | |
| # == Schema Information
 | |
| #
 | |
| # Table name: group_affinities
 | |
| #
 | |
| #  id         :bigint           not null, primary key
 | |
| #  discomfort :float            not null
 | |
| #  created_at :datetime         not null
 | |
| #  updated_at :datetime         not null
 | |
| #  group_a_id :uuid             not null
 | |
| #  group_b_id :uuid             not null
 | |
| #
 | |
| # Indexes
 | |
| #
 | |
| #  index_group_affinities_on_group_a_id  (group_a_id)
 | |
| #  index_group_affinities_on_group_b_id  (group_b_id)
 | |
| #  uindex_group_pair                     (LEAST(group_a_id, group_b_id), GREATEST(group_a_id, group_b_id)) UNIQUE
 | |
| #
 | |
| # Foreign Keys
 | |
| #
 | |
| #  fk_rails_...  (group_a_id => groups.id)
 | |
| #  fk_rails_...  (group_b_id => groups.id)
 | |
| #
 | |
| class GroupAffinity < ApplicationRecord
 | |
|   NEUTRAL = 1
 | |
|   MIN_DISCOMFORT = 0
 | |
|   MAX_DISCOMFORT = 2
 | |
| 
 | |
|   belongs_to :group_a, class_name: 'Group'
 | |
|   belongs_to :group_b, class_name: 'Group'
 | |
| 
 | |
|   validates :discomfort,
 | |
|             numericality: { greater_than_or_equal_to: MIN_DISCOMFORT, less_than_or_equal_to: MAX_DISCOMFORT }
 | |
| 
 | |
|   def another_group(group)
 | |
|     return nil if group != group_a && group != group_b
 | |
| 
 | |
|     group == group_a ? group_b : group_a
 | |
|   end
 | |
| end
 |