Module: Opencdd::MetaClass::MetaClasses

Defined in:
lib/opencdd/meta_class.rb

Constant Summary collapse

CODE_PROPERTY_IDS =
{
  "MDC_C002" => "MDC_P001_5",
  "MDC_C003" => "MDC_P001_6",
  "MDC_C005" => "MDC_P001_12",
  "MDC_C011" => "MDC_P001_13",
  "MDC_C009" => "MDC_P001_10",
  "MDC_C010" => "MDC_P001_11",
  "MDC_C0100" => "C0101",
  "EXT_C001" => "EXT_P001",
}.freeze
TYPE_BY_META_CLASS =
{
  "MDC_C002" => :class,
  "MDC_C003" => :property,
  "MDC_C005" => :value_list,
  "MDC_C011" => :relation,
  "MDC_C009" => :unit,
  "MDC_C010" => :value_term,
  "MDC_C0100" => :list_of_unit,
  "EXT_C001" => :view_control,
}.freeze

Class Method Summary collapse

Class Method Details

.allObject



116
117
118
119
# File 'lib/opencdd/meta_class.rb', line 116

def all
  ensure_loaded
  @registry.values
end

.code_property_id_for(irdi) ⇒ Object



136
137
138
# File 'lib/opencdd/meta_class.rb', line 136

def code_property_id_for(irdi)
  CODE_PROPERTY_IDS[irdi.to_s]
end

.codesObject



121
122
123
124
# File 'lib/opencdd/meta_class.rb', line 121

def codes
  ensure_loaded
  @registry.keys
end

.common_property_idsObject



100
101
102
# File 'lib/opencdd/meta_class.rb', line 100

def common_property_ids
  Opencdd::PropertyIds::REGISTRY.select { |_, e| e.applies_to == :all }.keys.freeze
end

.entity_class_for_type(type) ⇒ Object

Reverse of meta_class_for_type: returns the Ruby entity class (Opencdd::Klass, Opencdd::Property, etc.) registered for a given type Symbol. Single source of truth — used by Database#add_workbook to dispatch entity construction without maintaining its own type→class map.



145
146
147
148
149
150
# File 'lib/opencdd/meta_class.rb', line 145

def entity_class_for_type(type)
  code = meta_class_for_type(type)
  return nil unless code
  ensure_loaded
  @registry[code]&.entity_class
end

.for(irdi) ⇒ Object



111
112
113
114
# File 'lib/opencdd/meta_class.rb', line 111

def for(irdi)
  ensure_loaded
  @registry[irdi.to_s]
end

.meta_class_for_type(type) ⇒ Object



165
166
167
# File 'lib/opencdd/meta_class.rb', line 165

def meta_class_for_type(type)
  TYPE_BY_META_CLASS.key(type.to_sym) || TYPE_BY_META_CLASS.key(type.to_s.to_sym)
end

.register(meta_class) ⇒ Object



103
104
105
106
107
108
109
# File 'lib/opencdd/meta_class.rb', line 103

def register(meta_class)
  ensure_loaded
  existing = @registry[meta_class.irdi]
  merged = existing ? existing.merge(meta_class) : meta_class
  @registry[meta_class.irdi] = merged
  merged
end

.reset!Object



126
127
128
129
130
# File 'lib/opencdd/meta_class.rb', line 126

def reset!
  @registry = built_in_registry
  define_code_constants!
  self
end

.sheet_type_for(irdi) ⇒ Object



160
161
162
163
# File 'lib/opencdd/meta_class.rb', line 160

def sheet_type_for(irdi)
  ensure_loaded
  @registry[irdi.to_s]&.sheet_type
end

.sheet_type_for_type(type) ⇒ Object

Parcel sheet-type label ("CLASS", "PROPERTY", "ENUM", "TERMINOLOGY", "UoM", "RELATION", "VIEWCONTROL") for a given type Symbol. Used by Database#build_sheetmap_for and Parcel::Writer instead of local lookup tables.



156
157
158
# File 'lib/opencdd/meta_class.rb', line 156

def sheet_type_for_type(type)
  MetaClass::PARCEL_SHEET_TYPES[type.to_sym]
end

.type_for(irdi) ⇒ Object



132
133
134
# File 'lib/opencdd/meta_class.rb', line 132

def type_for(irdi)
  TYPE_BY_META_CLASS[irdi.to_s]
end