Class: Locomotive::RelationalAlgebra::Variable

Inherits:
Leaf show all
Defined in:
lib/locomotive/relational_algebra/operators/abstraction/variable.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Attributes inherited from Operator

#schema

Attributes included from AstHelpers::AstNode

#kind, #left_child, #owner, #right_child, #value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Operator

#bound, #to_xml, #xml_kind, #xml_schema

Methods included from XML

included, #quote, #to_xml

Methods included from AstHelpers::Annotations

#method_missing, #respond_to?

Methods included from AstHelpers::AstNode

#has_left_child?, #has_right_child?, #is_leaf?, #traverse, #traverse_strategy=

Constructor Details

#initialize(id, *items) ⇒ Variable

Returns a new instance of Variable.



24
25
26
27
28
29
30
31
32
33
# File 'lib/locomotive/relational_algebra/operators/abstraction/variable.rb', line 24

def initialize(id, *items)
  self.id,
  self.items = id, items
  Variable.id_pool << self.id
  self.schema = Schema.new({ Iter.new(1) => [RNat.type],
                             Pos.new(1) => [RNat.type] }.merge(
                               Hash[*items.collect do |it|
                                       [it, [RNat.instance]]
                                     end.flatten_once]) )
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Locomotive::AstHelpers::Annotations

Class Attribute Details

.id_poolObject

Returns the value of attribute id_pool.



8
9
10
# File 'lib/locomotive/relational_algebra/operators/abstraction/variable.rb', line 8

def id_pool
  @id_pool
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



18
19
20
# File 'lib/locomotive/relational_algebra/operators/abstraction/variable.rb', line 18

def id
  @id
end

#itemsObject

Returns the value of attribute items.



18
19
20
# File 'lib/locomotive/relational_algebra/operators/abstraction/variable.rb', line 18

def items
  @items
end

Class Method Details

.new_variable(*items) ⇒ Object



10
11
12
13
14
15
# File 'lib/locomotive/relational_algebra/operators/abstraction/variable.rb', line 10

def new_variable(*items)
  Variable.id_pool ||= [0]
  new_id = Variable.id_pool.max + 1
  Variable.id_pool << new_id
  Variable.new(new_id, *items)
end

Instance Method Details

#==(other) ⇒ Object



45
46
47
48
# File 'lib/locomotive/relational_algebra/operators/abstraction/variable.rb', line 45

def ==(other)
  other.class == Variable and
  other.id == self.id
end

#cloneObject



35
36
37
# File 'lib/locomotive/relational_algebra/operators/abstraction/variable.rb', line 35

def clone
  Variable.new(id, *items.clone)
end

#freeObject



58
59
60
# File 'lib/locomotive/relational_algebra/operators/abstraction/variable.rb', line 58

def free
  [ self.clone ]
end

#set(var, plan) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/locomotive/relational_algebra/operators/abstraction/variable.rb', line 50

def set(var,plan)
  if var == self
    plan.clone
  else
    self.clone
  end
end

#xml_contentObject



39
40
41
42
43
# File 'lib/locomotive/relational_algebra/operators/abstraction/variable.rb', line 39

def xml_content
  content do
    variable :name => id
  end
end