Class: Opencdd::MetaClass

Inherits:
Object
  • Object
show all
Defined in:
lib/opencdd/meta_class.rb

Overview

CDD is a four-layer ontology (IEC 61360 §5):

M2 (meta-model)  — the meta-classes themselves: MDC_C002 Class,
                 MDC_C003 Property, MDC_C009 Unit, etc.
                 Fixed set per the standard. Each is modeled
                 by an +Opencdd::MetaClass+ instance.
M1 (model)       — dictionary content: AAA001 Vehicle, AAAP001
                 vehicle_length, etc. Instances of M2
                 meta-classes, modeled by Opencdd::Entity
                 subclasses (Klass, Property, Unit, ...).
M0 (data)        — real-world individuals: ORCA30-TH-0001 etc.
                 Instances of M1 classes.

CDD's defining feature vs UML/RDF/OWL: at M1, a class declared class_type=CATEGORICAL_CLASS has subclasses that ARE themselves classes but are also "instances" of the categorical class in the powertype sense (used in CLASS_REFERENCE data types and sub_class_selection). This two-level capability is the central abstraction the model must preserve.

Defined Under Namespace

Modules: MetaClasses

Constant Summary collapse

PARCEL_SHEET_TYPES =

Parcel sheet-type label (string written to the sheetmap "type" column). Single source of truth — Database, Writer, and WorkbookReader all read from MetaClass#sheet_type instead of maintaining parallel lookup tables.

{
  class:        "CLASS",
  property:     "PROPERTY",
  value_list:   "ENUM",
  value_term:   "TERMINOLOGY",
  unit:         "UoM",
  relation:     "RELATION",
  view_control: "VIEWCONTROL",
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(irdi:, name:, entity_class: nil, allowed_property_ids: [], type: nil, sheet_type: nil) ⇒ MetaClass

Returns a new instance of MetaClass.



41
42
43
44
45
46
47
48
49
# File 'lib/opencdd/meta_class.rb', line 41

def initialize(irdi:, name:, entity_class: nil, allowed_property_ids: [],
               type: nil, sheet_type: nil)
  @irdi = irdi.to_s
  @name = name.to_s
  @entity_class = entity_class
  @allowed_property_ids = allowed_property_ids.map(&:to_s).freeze
  @type = type
  @sheet_type = sheet_type || (type ? PARCEL_SHEET_TYPES[type] : nil)
end

Instance Attribute Details

#allowed_property_idsObject (readonly)

Returns the value of attribute allowed_property_ids.



38
39
40
# File 'lib/opencdd/meta_class.rb', line 38

def allowed_property_ids
  @allowed_property_ids
end

#entity_classObject (readonly)

Returns the value of attribute entity_class.



38
39
40
# File 'lib/opencdd/meta_class.rb', line 38

def entity_class
  @entity_class
end

#irdiObject (readonly)

Returns the value of attribute irdi.



38
39
40
# File 'lib/opencdd/meta_class.rb', line 38

def irdi
  @irdi
end

#nameObject (readonly)

Returns the value of attribute name.



38
39
40
# File 'lib/opencdd/meta_class.rb', line 38

def name
  @name
end

#sheet_typeObject (readonly)

Returns the value of attribute sheet_type.



38
39
40
# File 'lib/opencdd/meta_class.rb', line 38

def sheet_type
  @sheet_type
end

#typeObject (readonly)

Returns the value of attribute type.



38
39
40
# File 'lib/opencdd/meta_class.rb', line 38

def type
  @type
end

Instance Method Details

#allows_property?(id) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/opencdd/meta_class.rb', line 53

def allows_property?(id)
  @allowed_property_ids.include?(id.to_s)
end

#codeObject



51
# File 'lib/opencdd/meta_class.rb', line 51

def code = @irdi

#merge(other) ⇒ Object

Raises:

  • (ArgumentError)


57
58
59
60
61
62
63
64
65
66
67
# File 'lib/opencdd/meta_class.rb', line 57

def merge(other)
  raise ArgumentError, "meta-class IRDI mismatch: #{other.irdi} != #{@irdi}" unless other.irdi == @irdi
  MetaClass.new(
    irdi: @irdi,
    name: @name,
    entity_class: @entity_class || other.entity_class,
    allowed_property_ids: (@allowed_property_ids + other.allowed_property_ids).uniq,
    type: @type || other.type,
    sheet_type: @sheet_type || other.sheet_type,
  )
end

#to_sObject Also known as: inspect



69
70
71
# File 'lib/opencdd/meta_class.rb', line 69

def to_s
  "#<#{self.class.name} #{@irdi} (#{@name}) type=#{@type} properties=#{@allowed_property_ids.size}>"
end