Class: MiniKraken::Core::Association

Inherits:
Object
  • Object
show all
Defined in:
lib/mini_kraken/core/association.rb

Overview

A record that a given variable is associated with a value.

Direct Known Subclasses

AssociationCopy

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aVariable, aValue) ⇒ Association

Returns a new instance of Association.

Parameters:

  • aVariable (Variable, String)

    A variable or its internal name.

  • aValue (Term)

    value being associated to the variable.



15
16
17
18
19
20
# File 'lib/mini_kraken/core/association.rb', line 15

def initialize(aVariable, aValue)
  a_name = aVariable.respond_to?(:i_name) ? aVariable.i_name : aVariable
  @i_name = validated_name(a_name)
  @value = aValue
  @dependencies = nil
end

Instance Attribute Details

#i_nameString

Returns internal name of variable being associated the value.

Returns:

  • (String)

    internal name of variable being associated the value.



8
9
10
# File 'lib/mini_kraken/core/association.rb', line 8

def i_name
  @i_name
end

#valueTerm (readonly)

Returns the MiniKraken value associated with the variable.

Returns:

  • (Term)

    the MiniKraken value associated with the variable



11
12
13
# File 'lib/mini_kraken/core/association.rb', line 11

def value
  @value
end

Instance Method Details

#dependencies(ctx) ⇒ Array<String>

Returns The i_names of direct dependent variables.

Returns:

  • (Array<String>)

    The i_names of direct dependent variables

Raises:

  • (StandardError)


40
41
42
43
44
45
# File 'lib/mini_kraken/core/association.rb', line 40

def dependencies(ctx)
  @dependencies ||= value.dependencies(ctx)
  raise StandardError unless @dependencies.kind_of?(Set) || @dependencies.kind_of?(NilClass)

  @dependencies
end

#floating?(ctx) ⇒ Boolean

Is the associated value floating, that is, it does contain a variable that is either unbound or floating?

Parameters:

Returns:

  • (Boolean)


26
27
28
# File 'lib/mini_kraken/core/association.rb', line 26

def floating?(ctx)
  value.floating?(ctx)
end

#pinned?(ctx) ⇒ Boolean

Is the associated value pinned, that is, doesn’t contain an unbound or floating variable?

Parameters:

Returns:

  • (Boolean)


34
35
36
37
# File 'lib/mini_kraken/core/association.rb', line 34

def pinned?(ctx)
  @pinned ||= value.pinned?(ctx)
  @pinned
end