Class: Plumb::SemanticMatcher::Nominal

Inherits:
Node
  • Object
show all
Defined in:
lib/plumb/semantic_matcher.rb

Instance Attribute Summary

Attributes inherited from Node

#raw

Instance Method Summary collapse

Methods inherited from Node

#equivalent?, #initialize, #intersect, #intersect_with_finite_set, #intersect_with_range, #overlap_with_finite_set, #overlap_with_numeric_literal, #overlap_with_opaque, #overlap_with_text_literal, #singleton?, #subset_from_opaque, #subset_from_text_literal, #value_domain

Constructor Details

This class inherits a constructor from Plumb::SemanticMatcher::Node

Instance Method Details

#error_messageObject



161
162
163
# File 'lib/plumb/semantic_matcher.rb', line 161

def error_message
  raw.is_a?(::Class) ? "Must be a #{raw}" : super
end

#kindObject



156
# File 'lib/plumb/semantic_matcher.rb', line 156

def kind = :nominal

#matcher_domainObject



158
# File 'lib/plumb/semantic_matcher.rb', line 158

def matcher_domain = raw.is_a?(::Class) ? [raw] : []

#matches_value(candidate) ⇒ Object



159
# File 'lib/plumb/semantic_matcher.rb', line 159

def matches_value(candidate) = Relation.from(raw === candidate)

#nominal?Boolean

Returns:

  • (Boolean)


157
# File 'lib/plumb/semantic_matcher.rb', line 157

def nominal? = true

#overlap(other) ⇒ Object



181
182
183
184
185
# File 'lib/plumb/semantic_matcher.rb', line 181

def overlap(other)
  return Relation::PROVEN if equivalent?(other)

  other.overlap_with_nominal(self)
end

#overlap_with_literal(other) ⇒ Object



194
# File 'lib/plumb/semantic_matcher.rb', line 194

def overlap_with_literal(other) = Relation.from(other.raw.is_a?(raw))

#overlap_with_nominal(other) ⇒ Object



187
188
189
190
191
192
# File 'lib/plumb/semantic_matcher.rb', line 187

def overlap_with_nominal(other)
  return Relation::PROVEN if subset_from_nominal(other).proven? || other.subset_from_nominal(self).proven?
  return Relation::DISPROVEN if raw.is_a?(::Class) && other.raw.is_a?(::Class)

  Relation::UNKNOWN # unrelated mixins may share an implementing class
end

#overlap_with_pattern(other) ⇒ Object



196
# File 'lib/plumb/semantic_matcher.rb', line 196

def overlap_with_pattern(other) = other.overlap_with_nominal(self)

#overlap_with_range(other) ⇒ Object



195
# File 'lib/plumb/semantic_matcher.rb', line 195

def overlap_with_range(other) = other.overlap_with_nominal(self)

#subset_from_finite_set(other) ⇒ Object



174
# File 'lib/plumb/semantic_matcher.rb', line 174

def subset_from_finite_set(other) = other.members_match(self)

#subset_from_literal(other) ⇒ Object



172
# File 'lib/plumb/semantic_matcher.rb', line 172

def subset_from_literal(other) = matches_value(other.raw)

#subset_from_nominal(other) ⇒ Object



171
# File 'lib/plumb/semantic_matcher.rb', line 171

def subset_from_nominal(other) = Relation.from((other.raw <= raw) == true)

#subset_from_numeric_literal(_other) ⇒ Object



173
# File 'lib/plumb/semantic_matcher.rb', line 173

def subset_from_numeric_literal(_other) = SemanticMatcher.wrap(::Numeric).subset_of(self)

#subset_from_pattern(other) ⇒ Object



177
178
179
# File 'lib/plumb/semantic_matcher.rb', line 177

def subset_from_pattern(other)
  Relation.all(other.matcher_domain.map { |domain| SemanticMatcher.wrap(domain).subset_of(self) })
end

#subset_from_range(other) ⇒ Object



175
# File 'lib/plumb/semantic_matcher.rb', line 175

def subset_from_range(other) = other.endpoints_within(self)

#subset_of(other) ⇒ Object



165
166
167
168
169
# File 'lib/plumb/semantic_matcher.rb', line 165

def subset_of(other)
  return Relation::PROVEN if equivalent?(other)

  other.subset_from_nominal(self)
end