Class: Opencdd::Database
- Inherits:
-
Object
- Object
- Opencdd::Database
- Includes:
- Enumerable
- Defined in:
- lib/opencdd/database.rb
Defined Under Namespace
Classes: Dictionary
Constant Summary collapse
- FORCED_META_CLASSES =
%w[MDC_C002 MDC_C003].freeze
- PARCEL_ID_PATTERN =
/\A[A-Z0-9-]+\z/.freeze
Instance Attribute Summary collapse
-
#alias_table ⇒ Object
readonly
Returns the value of attribute alias_table.
-
#unresolved_refs ⇒ Object
readonly
Returns the value of attribute unresolved_refs.
-
#workbooks ⇒ Object
readonly
Returns the value of attribute workbooks.
Class Method Summary collapse
- .from_yaml(yaml) ⇒ Object
- .load(path) ⇒ Object
- .load_flat_dir(path) ⇒ Object
- .load_from_directory(path) ⇒ Object
- .load_sharded_dir(path) ⇒ Object
- .load_workbook(path) ⇒ Object
Instance Method Summary collapse
- #add_dictionary(dict) ⇒ Object
- #add_entity(entity) ⇒ Object
- #add_workbook(workbook) ⇒ Object
-
#apply_change_request(cr, removals: []) ⇒ Object
Applies a Parcel change request (CR) to this database.
- #apply_view_control(klass, view_control) ⇒ Object
-
#categorical_classes ⇒ Object
All categorical classes registered in this database.
- #class_tree(fields: Opencdd::ClassTree::DEFAULT_FIELDS) ⇒ Object
- #classes ⇒ Object
- #classes_with_property(property) ⇒ Object
-
#coerce_entity(value) ⇒ Object
Coerce
value(Entity, IRDI, String, or nil) to an Entity. -
#coerce_irdi(value) ⇒ Object
Coerce
valueto an IRDI. - #composition_tree(klass, max_depth: 10) ⇒ Object
- #count(type = nil) ⇒ Object
- #dictionaries ⇒ Object
- #drop_dictionary(parcel_id) ⇒ Object
- #each(&block) ⇒ Object
-
#each_reference_collection ⇒ Object
Single iteration shape for any method that walks every set_of_refs property across every entity.
- #effective_properties ⇒ Object
- #entities ⇒ Object
- #entities_of_type(type) ⇒ Object
- #finalize! ⇒ Object
- #find(irdi) ⇒ Object
- #find_all_by_code(code) ⇒ Object
- #find_by_code(code) ⇒ Object
- #find_by_name(name, type: nil, lang: :en) ⇒ Object
- #functions_involving(property) ⇒ Object
-
#initialize ⇒ Database
constructor
A new instance of Database.
-
#instances_of(categorical_klass) ⇒ Object
Powertype instances of
categorical_klass— its valid options for CLASS_REFERENCE values. - #merge(other) ⇒ Object
- #normalize_reference_collections! ⇒ Object
- #properties ⇒ Object
- #properties_of(klass) ⇒ Object
- #register_entity_symbols(entity) ⇒ Object
- #register_external_sheet(sheet, parcel_id:) ⇒ Object
- #register_symbol(name, entity) ⇒ Object
- #relation_tree(root = nil, max_depth: 10) ⇒ Object
- #relations ⇒ Object
- #relations_for(domain: nil, codomain: nil) ⇒ Object
- #remove_by_irdi(ref) ⇒ Object
- #rename_entity(old_code, new_code) ⇒ Object
- #resolve_reference(ref) ⇒ Object
- #root_classes ⇒ Object
-
#save_to_directory(path) ⇒ Object
── Per-entity YAML persistence (lutaml-store) ─────────── One .yaml file per entity in a directory layout.
- #semantically_equal?(other) ⇒ Boolean
- #terms_of(value_list) ⇒ Object
- #to_s ⇒ Object (also: #inspect)
-
#to_yaml(*args) ⇒ Object
── YAML persistence (lutaml-model, CDD-native) ────────── Canonical YAML shape using semantic CDD attribute names (preferred_name, superclass, class_type) — not wire-format keys (MDC_P004, MDC_P010).
- #units ⇒ Object
-
#valid_class_reference?(categorical_klass, value) ⇒ Boolean
Predicate: is
valuea valid powertype instance of the given categorical class? Used by the validator's CLASS_REFERENCE check (R04/R08 extension). - #value_list_identifier_of(property) ⇒ Object
- #value_list_of(property) ⇒ Object
- #value_lists ⇒ Object
- #value_terms ⇒ Object
- #view_controls ⇒ Object
Constructor Details
#initialize ⇒ Database
Returns a new instance of Database.
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/opencdd/database.rb', line 31 def initialize @entities_by_irdi = {} @entities_by_code = Hash.new { |h, k| h[k] = [] } @entities_by_type = Hash.new { |h, k| h[k] = [] } @workbooks = [] @unresolved_refs = [] @class_by_property_irdi = nil @symbol_table = {} @alias_table = Opencdd::AliasTable.new(defaults: true) @entity_sources = {} end |
Instance Attribute Details
#alias_table ⇒ Object (readonly)
Returns the value of attribute alias_table.
13 14 15 |
# File 'lib/opencdd/database.rb', line 13 def alias_table @alias_table end |
#unresolved_refs ⇒ Object (readonly)
Returns the value of attribute unresolved_refs.
13 14 15 |
# File 'lib/opencdd/database.rb', line 13 def unresolved_refs @unresolved_refs end |
#workbooks ⇒ Object (readonly)
Returns the value of attribute workbooks.
13 14 15 |
# File 'lib/opencdd/database.rb', line 13 def workbooks @workbooks end |
Class Method Details
.from_yaml(yaml) ⇒ Object
511 512 513 514 |
# File 'lib/opencdd/database.rb', line 511 def self.from_yaml(yaml) ydb = Opencdd::Model::YamlDatabase.from_yaml(yaml) ydb.to_database end |
.load(path) ⇒ Object
15 16 17 |
# File 'lib/opencdd/database.rb', line 15 def self.load(path) Opencdd::Reader.load_database(path) end |
.load_flat_dir(path) ⇒ Object
23 24 25 |
# File 'lib/opencdd/database.rb', line 23 def self.load_flat_dir(path) Opencdd::Parcel::FlatDirReader.new(path).load_into(new) end |
.load_from_directory(path) ⇒ Object
526 527 528 |
# File 'lib/opencdd/database.rb', line 526 def self.load_from_directory(path) Opencdd::Model::EntityStore.new(path).load_database end |
.load_sharded_dir(path) ⇒ Object
27 28 29 |
# File 'lib/opencdd/database.rb', line 27 def self.load_sharded_dir(path) Opencdd::Parcel::ShardedDirReader.new(path).load_into(new) end |
.load_workbook(path) ⇒ Object
19 20 21 |
# File 'lib/opencdd/database.rb', line 19 def self.load_workbook(path) Opencdd::Parcel::WorkbookReader.new(path).load_into(new) end |
Instance Method Details
#add_dictionary(dict) ⇒ Object
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
# File 'lib/opencdd/database.rb', line 281 def add_dictionary(dict) validate_parcel_id!(dict.parcel_id) source_language = dict.source_language || "en" translation_languages = Array(dict.translation_languages) = (dict.) sheets = .map do || Opencdd::Parcel::Sheet.scaffold( meta_class_irdi: , parcel_id: dict.parcel_id, source_language: source_language, translation_languages: translation_languages, ) end project = Opencdd::Parcel::Workbook::ProjectInfo.new( project_id: dict.parcel_id, parcel_id: dict.parcel_id, multi_language: translation_languages.join(","), base_language: source_language, ) sheetmap = build_sheetmap_for(dict.parcel_id, sheets) workbook = Opencdd::Parcel::Workbook.new( sheets: sheets, sheetmap: sheetmap, project: project, ) @workbooks << workbook workbook end |
#add_entity(entity) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/opencdd/database.rb', line 68 def add_entity(entity) irdi = entity.irdi if irdi.nil? @unresolved_refs << [nil, entity] return self end if @entities_by_irdi.key?(irdi) existing = @entities_by_irdi[irdi] return self if existing.properties == entity.properties warn "Duplicate IRDI #{irdi} — overwriting" end @entities_by_irdi[irdi] = entity @entities_by_code[irdi.code] << entity if irdi.code @entities_by_type[entity.type] << entity if entity.type register_entity_symbols(entity) if entity.is_a?(Opencdd::Klass) entity.attach_database(self) end self end |
#add_workbook(workbook) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/opencdd/database.rb', line 43 def add_workbook(workbook) @workbooks << workbook parcel_id = workbook.parcel_id workbook.each_sheet do |sheet| next unless sheet.type && sheet.rows.any? type = sheet.type entity_class = Opencdd::MetaClasses.entity_class_for_type(type) raise "Unknown entity type #{type.inspect} for sheet #{sheet.name.inspect}" unless entity_class sheet.rows.each do |row| entity = entity_class.from_row( row, schema: sheet.schema, meta_class_irdi: sheet., ) add_entity(entity) if parcel_id && entity.irdi prev = @entity_sources[entity.irdi] @entity_sources[entity.irdi] = prev.nil? ? parcel_id : prev end end end self end |
#apply_change_request(cr, removals: []) ⇒ Object
Applies a Parcel change request (CR) to this database.
cr is a Opencdd::Database whose entities represent the
additions and updates to apply. removals: is an Array of
IRDIs (Strings or Opencdd::IRDI instances) identifying entities
to delete from this database.
Unlike #merge, which is purely additive, #apply_change_request
honors an explicit removal list. The CR's own entities are
upserted first (so an update-then-remove ordering resolves to
remove), then removals are applied.
Returns self for chaining.
480 481 482 483 484 485 486 |
# File 'lib/opencdd/database.rb', line 480 def apply_change_request(cr, removals: []) raise TypeError, "apply_change_request expects a Opencdd::Database" unless cr.is_a?(Opencdd::Database) cr.entities.each { |e| add_entity(e) } Array(removals).each { |r| remove_by_irdi(r) } finalize! self end |
#apply_view_control(klass, view_control) ⇒ Object
388 389 390 391 392 393 394 395 396 397 398 399 |
# File 'lib/opencdd/database.rb', line 388 def apply_view_control(klass, view_control) properties = effective_properties.for(klass).to_a return properties unless view_control.is_a?(Opencdd::ViewControl) controlled = view_control.controlled_class_irdis k = coerce_entity(klass) return properties unless k.is_a?(Opencdd::Klass) && controlled.include?(k.irdi) shown = view_control.shown_property_irdis lookup = properties.each_with_object({}) { |p, h| h[p.irdi] = p } shown.filter_map { |irdi| lookup[irdi] } end |
#categorical_classes ⇒ Object
All categorical classes registered in this database. Each is a candidate target for a CLASS_REFERENCE data type.
243 244 245 |
# File 'lib/opencdd/database.rb', line 243 def categorical_classes classes.select(&:powertype?) end |
#class_tree(fields: Opencdd::ClassTree::DEFAULT_FIELDS) ⇒ Object
265 266 267 |
# File 'lib/opencdd/database.rb', line 265 def class_tree(fields: Opencdd::ClassTree::DEFAULT_FIELDS) Opencdd::ClassTree.new(self, fields: fields) end |
#classes ⇒ Object
210 |
# File 'lib/opencdd/database.rb', line 210 def classes ; @entities_by_type[:class] || [] ; end |
#classes_with_property(property) ⇒ Object
407 408 409 410 411 |
# File 'lib/opencdd/database.rb', line 407 def classes_with_property(property) irdi = coerce_irdi(property) return [] unless irdi @class_by_property_irdi&.fetch(irdi, []) || [] end |
#coerce_entity(value) ⇒ Object
Coerce value (Entity, IRDI, String, or nil) to an Entity.
Returns nil if the value cannot be resolved. Single entry
point for the "entity or irdi" pattern that used to be
inlined at every call site.
175 176 177 178 179 |
# File 'lib/opencdd/database.rb', line 175 def coerce_entity(value) return nil if value.nil? return value if value.is_a?(Opencdd::Entity) find(value) end |
#coerce_irdi(value) ⇒ Object
Coerce value to an IRDI. Accepts an Entity (returns its
irdi), an IRDI (pass-through), or a String (parsed). Returns
nil if the value cannot be parsed.
184 185 186 187 188 189 |
# File 'lib/opencdd/database.rb', line 184 def coerce_irdi(value) return nil if value.nil? return value.irdi if value.is_a?(Opencdd::Entity) return value if value.is_a?(Opencdd::IRDI) Opencdd::IRDI.parse(value.to_s) end |
#composition_tree(klass, max_depth: 10) ⇒ Object
273 274 275 |
# File 'lib/opencdd/database.rb', line 273 def composition_tree(klass, max_depth: 10) Opencdd::CompositionTree.new(self).for(klass, max_depth: max_depth) end |
#count(type = nil) ⇒ Object
226 227 228 |
# File 'lib/opencdd/database.rb', line 226 def count(type = nil) type ? (@entities_by_type[type] || []).size : @entities_by_irdi.size end |
#dictionaries ⇒ Object
338 339 340 341 342 343 344 345 346 347 |
# File 'lib/opencdd/database.rb', line 338 def dictionaries @workbooks.map do |wb| Dictionary.new( parcel_id: wb.parcel_id, source_language: wb.base_language, translation_languages: parse_translation_languages(wb), meta_class_irdis: wb.sheets.map(&:meta_class_irdi).compact.uniq, ) end end |
#drop_dictionary(parcel_id) ⇒ Object
310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'lib/opencdd/database.rb', line 310 def drop_dictionary(parcel_id) matching = @workbooks.select { |wb| wb.parcel_id == parcel_id } raise ArgumentError, "no dictionary with parcel_id #{parcel_id.inspect}" if matching.empty? irdis_to_drop = @entity_sources.select { |_, pid| pid == parcel_id }.keys irdis_to_drop.each do |irdi| remove_entity_by_irdi!(irdi) @entity_sources.delete(irdi) end @workbooks.reject! { |wb| wb.parcel_id == parcel_id } self end |
#each(&block) ⇒ Object
496 497 498 |
# File 'lib/opencdd/database.rb', line 496 def each(&block) @entities_by_irdi.each_value(&block) end |
#each_reference_collection ⇒ Object
Single iteration shape for any method that walks every
set_of_refs property across every entity. Yields
(entity, property_id, raw_value, elements) where elements
is the unwrapped Array
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/opencdd/database.rb', line 148 def each_reference_collection return enum_for(:each_reference_collection) unless block_given? set_property_ids = Opencdd::PropertyIds::REGISTRY .select { |_, e| e.value_kind == :set_of_refs } .keys entities.each do |entity| set_property_ids.each do |pid| raw = entity.properties[pid] next if raw.nil? || raw.to_s.strip.empty? elements = Opencdd::StructuredValues.unwrap_and_split(raw) next if elements.empty? yield(entity, pid, raw, elements) end end end |
#effective_properties ⇒ Object
269 270 271 |
# File 'lib/opencdd/database.rb', line 269 def effective_properties @effective_properties ||= Opencdd::EffectiveProperties.new(self) end |
#entities ⇒ Object
222 223 224 |
# File 'lib/opencdd/database.rb', line 222 def entities @entities_by_irdi.values end |
#entities_of_type(type) ⇒ Object
218 219 220 |
# File 'lib/opencdd/database.rb', line 218 def entities_of_type(type) @entities_by_type[type.to_sym] || [] end |
#finalize! ⇒ Object
127 128 129 130 131 132 133 134 |
# File 'lib/opencdd/database.rb', line 127 def finalize! normalize_reference_collections! link_class_hierarchy! link_property_classes! link_value_lists! rebuild_symbol_table! self end |
#find(irdi) ⇒ Object
164 165 166 167 168 169 |
# File 'lib/opencdd/database.rb', line 164 def find(irdi) return nil if irdi.nil? key = Opencdd::IRDI === irdi ? irdi : Opencdd::IRDI.parse(irdi) return nil unless key @entities_by_irdi[key] end |
#find_all_by_code(code) ⇒ Object
197 198 199 |
# File 'lib/opencdd/database.rb', line 197 def find_all_by_code(code) @entities_by_code[code.to_s].dup end |
#find_by_code(code) ⇒ Object
191 192 193 194 195 |
# File 'lib/opencdd/database.rb', line 191 def find_by_code(code) matches = @entities_by_code[code.to_s] return nil if matches.empty? matches.first end |
#find_by_name(name, type: nil, lang: :en) ⇒ Object
201 202 203 204 205 206 207 208 |
# File 'lib/opencdd/database.rb', line 201 def find_by_name(name, type: nil, lang: :en) pools = type ? [@entities_by_type[type]].compact : @entities_by_type.values pools.each do |pool| hit = pool.find { |e| e.preferred_name(lang).to_s.casecmp(name.to_s).zero? } return hit if hit end nil end |
#functions_involving(property) ⇒ Object
452 453 454 455 456 457 458 |
# File 'lib/opencdd/database.rb', line 452 def functions_involving(property) irdi = coerce_irdi(property) return [] unless irdi relations.select do |r| r.function? && (r.domain_irdis.include?(irdi) || r.codomain_irdi == irdi) end end |
#instances_of(categorical_klass) ⇒ Object
Powertype instances of categorical_klass — its valid options
for CLASS_REFERENCE values. Accepts a Klass, IRDI, or code
String. Returns [] if categorical_klass is not a powertype.
250 251 252 253 254 |
# File 'lib/opencdd/database.rb', line 250 def instances_of(categorical_klass) k = coerce_entity(categorical_klass) return [] unless k.is_a?(Opencdd::Klass) k.categorical_instances(self) end |
#merge(other) ⇒ Object
460 461 462 463 464 465 |
# File 'lib/opencdd/database.rb', line 460 def merge(other) raise TypeError, "merge expects a Opencdd::Database" unless other.is_a?(Opencdd::Database) other.entities.each { |e| add_entity(e) } finalize! self end |
#normalize_reference_collections! ⇒ Object
136 137 138 139 140 141 |
# File 'lib/opencdd/database.rb', line 136 def normalize_reference_collections! each_reference_collection do |entity, pid, _raw, elements| entity.properties[pid] = Opencdd::StructuredValues.rejoin(elements) end self end |
#properties ⇒ Object
211 |
# File 'lib/opencdd/database.rb', line 211 def properties ; @entities_by_type[:property] || [] ; end |
#properties_of(klass) ⇒ Object
401 402 403 404 405 |
# File 'lib/opencdd/database.rb', line 401 def properties_of(klass) k = coerce_entity(klass) return [] unless k.is_a?(Opencdd::Klass) k.properties_on_class(self) end |
#register_entity_symbols(entity) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/opencdd/database.rb', line 97 def register_entity_symbols(entity) name = entity.is_a?(Opencdd::Entity) ? entity.preferred_name : nil bind_symbol(name, entity) if name code = entity.code bind_symbol(code, entity) if code self end |
#register_external_sheet(sheet, parcel_id:) ⇒ Object
323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
# File 'lib/opencdd/database.rb', line 323 def register_external_sheet(sheet, parcel_id:) validate_parcel_id!(parcel_id) wb = @workbooks.find { |w| w.parcel_id == parcel_id } if wb.nil? project = Opencdd::Parcel::Workbook::ProjectInfo.new( project_id: parcel_id, parcel_id: parcel_id, multi_language: "", base_language: "en", ) wb = Opencdd::Parcel::Workbook.new(sheets: [], sheetmap: [], project: project) @workbooks << wb end wb.register_sheet(sheet) self end |
#register_symbol(name, entity) ⇒ Object
93 94 95 |
# File 'lib/opencdd/database.rb', line 93 def register_symbol(name, entity) bind_symbol(name, entity) end |
#relation_tree(root = nil, max_depth: 10) ⇒ Object
277 278 279 |
# File 'lib/opencdd/database.rb', line 277 def relation_tree(root = nil, max_depth: 10) Opencdd::RelationTree.new(self).for(root, max_depth: max_depth) end |
#relations ⇒ Object
215 |
# File 'lib/opencdd/database.rb', line 215 def relations ; @entities_by_type[:relation] || [] ; end |
#relations_for(domain: nil, codomain: nil) ⇒ Object
443 444 445 446 447 448 449 450 |
# File 'lib/opencdd/database.rb', line 443 def relations_for(domain: nil, codomain: nil) dom = coerce_irdi(domain) cod = coerce_irdi(codomain) relations.select do |r| (dom.nil? || r.domain_irdis.include?(dom)) && (cod.nil? || r.codomain_irdi == cod) end end |
#remove_by_irdi(ref) ⇒ Object
488 489 490 491 492 493 494 |
# File 'lib/opencdd/database.rb', line 488 def remove_by_irdi(ref) irdi = ref.is_a?(Opencdd::IRDI) ? ref : Opencdd::IRDI.parse(ref.to_s) return unless irdi remove_entity_by_irdi!(irdi) @entity_sources.delete(irdi) self end |
#rename_entity(old_code, new_code) ⇒ Object
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
# File 'lib/opencdd/database.rb', line 349 def rename_entity(old_code, new_code) old_code_s = old_code.to_s new_code_s = new_code.to_s return self if old_code_s == new_code_s target = find_by_code(old_code_s) return self unless target clash = find_by_code(new_code_s) if clash && clash.irdi != target.irdi warn "Cannot rename #{old_code_s} → #{new_code_s}: target code already in use by #{clash.irdi}" return self end old_irdi = target.irdi new_irdi = old_irdi.with_code(new_code_s) @entities_by_irdi.delete(old_irdi) @entities_by_code[old_code_s].delete(target) ref_property_ids = Opencdd::PropertyIds::REGISTRY.select do |_, e| REFERENCE_VALUE_KINDS.include?(e.value_kind) end.keys entities.each do |entity| rewrite_back_references!(entity, old_irdi, new_irdi, ref_property_ids) end code_pid = target.class.default_code_property_id(target.) target.replace_code_value!(code_pid, new_code_s) target.replace_irdi!(new_irdi) @entities_by_irdi[new_irdi] = target @entities_by_code[new_code_s] << target rebuild_symbol_table! self end |
#resolve_reference(ref) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/opencdd/database.rb', line 105 def resolve_reference(ref) return nil if ref.nil? return ref if ref.is_a?(Opencdd::Entity) key = ref.to_s.strip return nil if key.empty? if key.include?("/") || key.include?("#") irdi = Opencdd::IRDI.parse(key) return find(irdi) end entity = @symbol_table[key] return entity if entity by_code = find_by_code(key) return by_code if by_code irdi = Opencdd::IRDI.parse(key) irdi ? find(irdi) : nil end |
#root_classes ⇒ Object
230 231 232 |
# File 'lib/opencdd/database.rb', line 230 def root_classes classes.select { |c| c.parent_irdi.nil? } end |
#save_to_directory(path) ⇒ Object
── Per-entity YAML persistence (lutaml-store) ─────────── One .yaml file per entity in a directory layout. Diff-friendly at the entity level — one git diff shows exactly what changed. See TODO.impl/34.
521 522 523 524 |
# File 'lib/opencdd/database.rb', line 521 def save_to_directory(path) Opencdd::Model::EntityStore.new(path).save_database(self) self end |
#semantically_equal?(other) ⇒ Boolean
530 531 532 533 534 535 536 537 |
# File 'lib/opencdd/database.rb', line 530 def semantically_equal?(other) return false unless other.is_a?(Opencdd::Database) return false unless entities.size == other.entities.size entities.all? do |e| oe = other.find(e.irdi) oe && e.type == oe.type && e.properties == oe.properties end end |
#terms_of(value_list) ⇒ Object
438 439 440 441 |
# File 'lib/opencdd/database.rb', line 438 def terms_of(value_list) return [] if value_list.nil? value_list.term_irdis.map { |i| find(i) }.compact end |
#to_s ⇒ Object Also known as: inspect
539 540 541 542 543 |
# File 'lib/opencdd/database.rb', line 539 def to_s "#<#{self.class.name} classes=#{classes.size} properties=#{properties.size} " \ "units=#{units.size} value_lists=#{value_lists.size} value_terms=#{value_terms.size} " \ "relations=#{relations.size}>" end |
#to_yaml(*args) ⇒ Object
── YAML persistence (lutaml-model, CDD-native) ────────── Canonical YAML shape using semantic CDD attribute names (preferred_name, superclass, class_type) — not wire-format keys (MDC_P004, MDC_P010). See TODO.impl/33.
507 508 509 |
# File 'lib/opencdd/database.rb', line 507 def to_yaml(*args) Opencdd::Model::YamlDatabase.from_database(self).to_yaml(*args) end |
#units ⇒ Object
212 |
# File 'lib/opencdd/database.rb', line 212 def units ; @entities_by_type[:unit] || [] ; end |
#valid_class_reference?(categorical_klass, value) ⇒ Boolean
Predicate: is value a valid powertype instance of the given
categorical class? Used by the validator's CLASS_REFERENCE
check (R04/R08 extension).
259 260 261 262 263 |
# File 'lib/opencdd/database.rb', line 259 def valid_class_reference?(categorical_klass, value) target = coerce_entity(value) return false unless target instances_of(categorical_klass).any? { |c| c.irdi == target.irdi } end |
#value_list_identifier_of(property) ⇒ Object
431 432 433 434 435 436 |
# File 'lib/opencdd/database.rb', line 431 def value_list_identifier_of(property) case property.parsed_data_type when Opencdd::DataType::EnumStringType, Opencdd::DataType::EnumReferenceType property.parsed_data_type.value_list_identifier end end |
#value_list_of(property) ⇒ Object
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
# File 'lib/opencdd/database.rb', line 413 def value_list_of(property) prop = coerce_entity(property) return nil unless prop.is_a?(Opencdd::Property) relations.each do |r| next unless r.predication? next unless r.domain_irdis.include?(prop.irdi) vl = r.codomain_irdi && find(r.codomain_irdi) return vl if vl.is_a?(Opencdd::ValueList) end return nil unless prop.enum? identifier = value_list_identifier_of(prop) return nil unless identifier vl = resolve_reference(identifier) vl if vl.is_a?(Opencdd::ValueList) end |
#value_lists ⇒ Object
213 |
# File 'lib/opencdd/database.rb', line 213 def value_lists ; @entities_by_type[:value_list] || [] ; end |
#value_terms ⇒ Object
214 |
# File 'lib/opencdd/database.rb', line 214 def value_terms ; @entities_by_type[:value_term] || [] ; end |
#view_controls ⇒ Object
216 |
# File 'lib/opencdd/database.rb', line 216 def view_controls ; @entities_by_type[:view_control] || [] ; end |