Class: Opencdd::Condition::ClassReference
- Inherits:
-
Condition
- Object
- Condition
- Opencdd::Condition::ClassReference
- 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 overridesatisfied_by?. [:class, :host_class, "class", "host_class"].freeze
Instance Attribute Summary collapse
-
#irdis ⇒ Object
readonly
Returns the value of attribute irdis.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #class_reference? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(irdis:) ⇒ ClassReference
constructor
A new instance of ClassReference.
- #satisfied_by?(bindings) ⇒ Boolean
- #set? ⇒ Boolean
- #to_s ⇒ Object
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
#irdis ⇒ Object (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
156 157 158 |
# File 'lib/opencdd/condition.rb', line 156 def class_reference? true end |
#hash ⇒ Object
180 181 182 |
# File 'lib/opencdd/condition.rb', line 180 def hash Set.new(@irdis).hash end |
#satisfied_by?(bindings) ⇒ 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
160 161 162 |
# File 'lib/opencdd/condition.rb', line 160 def set? @irdis.size > 1 end |
#to_s ⇒ Object
171 172 173 |
# File 'lib/opencdd/condition.rb', line 171 def to_s @irdis.size == 1 ? @irdis.first : "{#{@irdis.join(', ')}}" end |