Module: Edoxen::BodyVocabularyHost

Included in:
DecisionMetadata, MeetingCollectionMetadata
Defined in:
lib/edoxen/body_vocabulary_host.rb

Overview

Mixed into metadata classes that carry a per-dataset body_vocabulary[] collection (v2.1, TODO.refactor/46). Provides the attribute declaration and the canonical_type_for lookup in one place so DecisionMetadata and MeetingCollectionMetadata share a single implementation.

Permissive by design: when no vocabulary entry matches a body_type, the body_type string itself is returned (with no warning). Strict mode is a v3.x concern.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



14
15
16
# File 'lib/edoxen/body_vocabulary_host.rb', line 14

def self.included(base)
  base.attribute :body_vocabulary, BodyVocabularyEntry, collection: true
end

Instance Method Details

#canonical_type_for(body_type) ⇒ Object

Resolve a body_type to its canonical_type via this collection's vocabulary. Returns the body_type unchanged when nil/empty or when no matching entry exists.



21
22
23
24
25
26
27
# File 'lib/edoxen/body_vocabulary_host.rb', line 21

def canonical_type_for(body_type)
  return body_type if body_type.nil? || body_type.to_s.empty?
  return body_type unless body_vocabulary

  entry = body_vocabulary.find { |e| e.body_type == body_type }
  entry ? entry.canonical_type : body_type
end