motor_code = 'F01.145.632'
parents = descriptor_code_hash.select do |k, v|
motor_code[/^#{k}/] && motor_code != k
end.map { |k, v| v }
# => ["Behavior and Behavior Mechanisms", "Behavior"]
siblings = descriptor_code_hash.select do |k, v|
k =~ /^#{motor_code.split('.')[0..-2].join('\.')}\.\d{3}/ && k != motor_code
end.map { |k, v| v }
# => ["Information Seeking Behavior", "Inhibition (Psychology)", "Freezing Reaction, Cataleptic", "Immobility Response, Tonic"]
children = descriptor_code_hash.select do |k, v|
k =~ /^#{motor_code}\.[\d\.]*/
end.map { |k, v| v }
# => ["Freezing Reaction, Cataleptic", "Immobility Response, Tonic"]
parents
are found by looking for all keys which are prefixes to the motor_code
.
siblings
are found by looking for all keys which are prefixed by the parent key of motor_code
(removing the last three digits, and expecting exactly three digits.
children
are found by looking for all keys which are prefixed by motor_code