Class: Opencdd::Property

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

Constant Summary collapse

DATA_TYPE_ALIASES =

Wire-format aliases for the data_type string. Used by #data_type to canonicalize the raw value before exposing it.

{
  "STRING_TYPE"              => :string,
  "TRANSLATABLE_STRING_TYPE" => :translatable_string,
  "REAL_MEASURE_TYPE"        => :real_measure,
  "INTEGER_MEASURE_TYPE"     => :integer_measure,
  "INT_MEASURE_TYPE"         => :integer_measure,
  "REAL_TYPE"                => :real,
  "INTEGER_TYPE"             => :integer,
  "INT_TYPE"                 => :integer,
  "BOOLEAN_TYPE"             => :boolean,
  "DATE_TYPE"                => :date,
  "DATETIME_TYPE"            => :date_time,
  "DATE_TIME_TYPE"           => :date_time,
  "TIME_TYPE"                => :time,
  "IRDI_TYPE"                => :irdi,
  "ICID_STRING"              => :irdi,
  "ICID_STRING_TYPE"         => :irdi,
  "URL_TYPE"                 => :url,
  "MIME_TYPE"                => :mime,
  "FILE_TYPE"                => :file,
  "COMPLEX_TYPE"             => :complex,
}.freeze
PARSED_DATA_TYPE_BLOCK =

── Computed fields with block-form readers (synthetic: true). Blocks are evaluated via instance_exec on the entity, so they have access to private helpers without send dispatch. data_type is NOT a DSL field — the model's #data_type method returns a symbol (:real, :string, etc.) for callers. The wire- format string ("REAL_TYPE") comes from parsed_data_type.to_s and is emitted explicitly by Exporters::Json#property_node.

lambda {
  Opencdd::DataType.parse_or_string(properties[Opencdd::PropertyIds::MDC_P022])
}
DATA_ELEMENT_TYPE_BLOCK =
lambda {
  @property_data_element_type ||=
    Opencdd::PropertyDataTypeElement.parse(properties[Opencdd::PropertyIds::MDC_P020])
}

Instance Method Summary collapse

Instance Method Details

#active_for?(bindings) ⇒ Boolean

Returns:

  • (Boolean)


108
109
110
111
112
# File 'lib/opencdd/property.rb', line 108

def active_for?(bindings)
  return true unless conditional?
  cond = condition
  cond ? cond.satisfied_by?(bindings) : true
end

#attaches_to(*_args) ⇒ Object Also known as: applies_to

Raises:

  • (NotImplementedError)


114
115
116
117
# File 'lib/opencdd/property.rb', line 114

def attaches_to(*_args)
  raise NotImplementedError,
        "Property#attaches_to is provided by Opencdd::Database; use db.properties_of(klass)"
end

#class_reference?Boolean

── Predicates and methods with arguments stay as regular methods. The DSL is for fields, not behavior. ───────────

Returns:

  • (Boolean)


94
95
96
# File 'lib/opencdd/property.rb', line 94

def class_reference?
  parsed_data_type.is_a?(Opencdd::DataType::ClassReference)
end

#conditional?Boolean

Returns:

  • (Boolean)


103
104
105
106
# File 'lib/opencdd/property.rb', line 103

def conditional?
  det = property_data_element_type
  det && (det.condition? || det.dependent?)
end

#data_typeObject

Model-side data_type — returns the canonical symbol form.



86
87
88
89
# File 'lib/opencdd/property.rb', line 86

def data_type
  raw = properties[Opencdd::PropertyIds::MDC_P022]
  DATA_TYPE_ALIASES[raw] || raw
end

#enum?Boolean

Returns:

  • (Boolean)


98
99
100
101
# File 'lib/opencdd/property.rb', line 98

def enum?
  parsed_data_type.is_a?(Opencdd::DataType::EnumStringType) ||
    parsed_data_type.is_a?(Opencdd::DataType::EnumReferenceType)
end