wedding-planner/app/services/affinity_groups_hierarchy.rb
Manuel Bustillo b7cabc1661
All checks were successful
Add copyright notice / copyright_notice (pull_request) Successful in 3m21s
Run unit tests / unit_tests (pull_request) Successful in 2m49s
Build Nginx-based docker image / build-static-assets (pull_request) Successful in 31m54s
Add copyright notice
2024-10-27 21:42:45 +00:00

30 lines
677 B
Ruby

# Copyright (C) 2024 Manuel Bustillo
class AffinityGroupsHierarchy < Array
include Singleton
def initialize
super
@references = {}
end
def find(name)
@references[name]
end
def <<(name)
new_node = Tree::TreeNode.new(name)
super(new_node).tap { @references[name] = new_node }
end
def register_child(parent_name, child_name)
@references[parent_name] << Tree::TreeNode.new(child_name).tap { |child_node| @references[child_name] = child_node }
end
def distance(name_a, name_b)
return nil if @references[name_a].nil? || @references[name_b].nil?
@references[name_a].distance_to_common_ancestor(@references[name_b])
end
end