Class: Locomotive::RelationalAlgebra::Comparison

Inherits:
Unary show all
Defined in:
lib/locomotive/relational_algebra/operators/comparisons/basic_comparison.rb

Instance Attribute Summary collapse

Attributes inherited from Operator

#schema

Attributes included from AstHelpers::AstNode

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

Instance Method Summary collapse

Methods inherited from Operator

#bound, #free, #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(op, res, items) ⇒ Comparison

Returns a new instance of Comparison.



14
15
16
17
18
19
# File 'lib/locomotive/relational_algebra/operators/comparisons/basic_comparison.rb', line 14

def initialize(op, res, items)
  self.res,
  self.item1,
  self.item2 = res, items[0], items[1]
  super(op)
end

Dynamic Method Handling

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

Instance Attribute Details

#item1Object

Returns the value of attribute item1.



7
8
9
# File 'lib/locomotive/relational_algebra/operators/comparisons/basic_comparison.rb', line 7

def item1
  @item1
end

#item2Object

Returns the value of attribute item2.



7
8
9
# File 'lib/locomotive/relational_algebra/operators/comparisons/basic_comparison.rb', line 7

def item2
  @item2
end

#resObject

Returns the value of attribute res.



7
8
9
# File 'lib/locomotive/relational_algebra/operators/comparisons/basic_comparison.rb', line 7

def res
  @res
end

Instance Method Details

#child=(op) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/locomotive/relational_algebra/operators/comparisons/basic_comparison.rb', line 21

def child=(op)
  unless op.schema.attributes?([self.item1])
    raise CorruptedSchema,
          "Schema #{op.schema.attributes} does not " \
          "contain all attributes of #{item1}."
  end
  unless op.schema.attributes?([self.item2])
    raise CorruptedSchema,
          "Schema #{op.schema.attributes} does not " \
          "contain all attributes of #{item2}."
  end
    
  self.schema = op.schema + Schema.new({ self.res => [RBool.instance]})
  super(op)
end

#cloneObject



37
38
39
40
41
42
# File 'lib/locomotive/relational_algebra/operators/comparisons/basic_comparison.rb', line 37

def clone
  self.class.new(child.clone,
                 res.clone,
                 [item1.clone,
                  item2.clone])
end

#set(var, plan) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/locomotive/relational_algebra/operators/comparisons/basic_comparison.rb', line 44

def set(var,plan)
  self.class.new(
    child.set(var,plan),
    res.clone,
    [item1.clone,
    item2.clone])
end

#xml_contentObject



52
53
54
55
56
57
58
59
60
# File 'lib/locomotive/relational_algebra/operators/comparisons/basic_comparison.rb', line 52

def xml_content
      content do
    [column(:name => res.to_xml, :new => true),
     column(:name => item1.to_xml, :new => false, :position => 1),
     column(:name => item2.to_xml, :new => false, :position => 2)
    ].join
  end
    
end