Class: Opencdd::Condition::ClassReference

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

Overview

A condition of the form {0112/2///62683#ACE132} or a bare 0112/2///62683#ACE132 — meaning "this property applies when the host class is one of the listed IRDIs". IEC 62683 stores property conditions this way; the regular boolean-expression grammar in Condition cannot represent it.

Constant Summary collapse

HOST_CLASS_KEYS =

The binding key (string or symbol) consulted by #satisfied_by? to discover the host class IRDI. Callers that resolve the host class via a different key should override satisfied_by?.

[:class, :host_class, "class", "host_class"].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(irdis:) ⇒ ClassReference

Returns a new instance of ClassReference.



149
150
151
152
153
154
# File 'lib/opencdd/condition.rb', line 149

def initialize(irdis:)
  @irdis = Array(irdis).map(&:to_s)
  @left = nil
  @operator = nil
  @right = nil
end

Instance Attribute Details

#irdisObject (readonly)

Returns the value of attribute irdis.



142
143
144
# File 'lib/opencdd/condition.rb', line 142

def irdis
  @irdis
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



175
176
177
# File 'lib/opencdd/condition.rb', line 175

def ==(other)
  other.is_a?(ClassReference) && Set.new(@irdis) == Set.new(other.irdis)
end

#class_reference?Boolean

Returns:

  • (Boolean)


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

def class_reference?
  true
end

#hashObject



180
181
182
# File 'lib/opencdd/condition.rb', line 180

def hash
  Set.new(@irdis).hash
end

#satisfied_by?(bindings) ⇒ Boolean

Returns:

  • (Boolean)


164
165
166
167
168
169
# File 'lib/opencdd/condition.rb', line 164

def satisfied_by?(bindings)
  hash = bindings.is_a?(Hash) ? bindings : bindings.to_h
  actual = HOST_CLASS_KEYS.map { |k| hash[k] }.compact.first
  return true if actual.nil?
  @irdis.any? { |irdi| actual.to_s == irdi }
end

#set?Boolean

Returns:

  • (Boolean)


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

def set?
  @irdis.size > 1
end

#to_sObject



171
172
173
# File 'lib/opencdd/condition.rb', line 171

def to_s
  @irdis.size == 1 ? @irdis.first : "{#{@irdis.join(', ')}}"
end