Class: MiniKraken::Core::LogVarRef
- Defined in:
- lib/mini_kraken/core/log_var_ref.rb
Overview
Representation of a reference to a MiniKraken logical variable.
Instance Attribute Summary collapse
-
#i_name ⇒ String
Unique internal name of the variable.
-
#name ⇒ String
readonly
User-friendly name of the variable.
Instance Method Summary collapse
-
#dependencies(ctx) ⇒ Set<String>
Return the list of variable (i_names) that this term depends on.
-
#dup_cond(substitutions) ⇒ Term
Make a copy of self with all the variable reference being replaced by the corresponding value in the Hash.
-
#floating?(aContext) ⇒ Boolean
Does the variable have at least one association AND each of these association refer to at least one unbound variable or a floating variable?.
-
#initialize(aName) ⇒ LogVarRef
constructor
Create a reference to a logical variable with given name.
-
#pinned?(aContext) ⇒ Boolean
Is the variable pinned? In other words, does the referenced variable have a definite value?.
-
#to_s ⇒ String
Return a text representation of this logical variable reference.
-
#unbound?(aContext) ⇒ Boolean
Is the related log variable unbound in the given context? A log var is unbound when there is no association for the variable.
Constructor Details
#initialize(aName) ⇒ LogVarRef
Create a reference to a logical variable with given name
18 19 20 21 |
# File 'lib/mini_kraken/core/log_var_ref.rb', line 18 def initialize(aName) super() init_name(aName) end |
Instance Attribute Details
#i_name ⇒ String
Returns Unique internal name of the variable.
14 15 16 |
# File 'lib/mini_kraken/core/log_var_ref.rb', line 14 def i_name @i_name end |
#name ⇒ String (readonly)
Returns User-friendly name of the variable.
11 12 13 |
# File 'lib/mini_kraken/core/log_var_ref.rb', line 11 def name @name end |
Instance Method Details
#dependencies(ctx) ⇒ Set<String>
Return the list of variable (i_names) that this term depends on. For a variable reference, it will return the i_names of its variable
80 81 82 83 84 85 |
# File 'lib/mini_kraken/core/log_var_ref.rb', line 80 def dependencies(ctx) @i_name ||= ctx.lookup(name).i_name s = Set.new s << i_name s end |
#dup_cond(substitutions) ⇒ Term
Make a copy of self with all the variable reference being replaced by the corresponding value in the Hash.
91 92 93 94 95 96 97 98 99 |
# File 'lib/mini_kraken/core/log_var_ref.rb', line 91 def dup_cond(substitutions) key = i_name || name if substitutions.include? key val = substitutions[key] val.kind_of?(Term) ? val.dup_cond(substitutions) : val else dup end end |
#floating?(aContext) ⇒ Boolean
Does the variable have at least one association AND each of these association refer to at least one unbound variable or a floating variable?
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/mini_kraken/core/log_var_ref.rb', line 46 def floating?(aContext) vr = aContext.lookup(name) raise StandardError, "Unknown variable #{name}" unless vr assocs = aContext.associations_for(name) unless assocs.empty? assocs.none? { |as| as.pinned?(aContext) } else false end end |
#pinned?(aContext) ⇒ Boolean
Is the variable pinned? In other words, does the referenced variable have a definite value?
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/mini_kraken/core/log_var_ref.rb', line 62 def pinned?(aContext) return true if @pinned vr = aContext.lookup(name) raise StandardError, "Unknown variable #{name}" unless vr assocs = aContext.associations_for(name) unless assocs.empty? @pinned = assocs.all? { |as| as.pinned?(aContext) } else false end end |
#to_s ⇒ String
Return a text representation of this logical variable reference.
25 26 27 |
# File 'lib/mini_kraken/core/log_var_ref.rb', line 25 def to_s name end |
#unbound?(aContext) ⇒ Boolean
Is the related log variable unbound in the given context? A log var is unbound when there is no association for the variable.
33 34 35 36 37 38 39 |
# File 'lib/mini_kraken/core/log_var_ref.rb', line 33 def unbound?(aContext) vr = aContext.lookup(name) raise StandardError, "Unknown variable #{name}" unless vr bindings = aContext.associations_for(name) bindings.empty? || (bindings.size == 1 && bindings[0].kind_of?(Fusion)) end |