Class: Locomotive::RelationalAlgebra::ConstAttribute

Inherits:
GenericAttribute show all
Includes:
HashKeys
Defined in:
lib/locomotive/relational_algebra/attributes.rb

Direct Known Subclasses

Item, Iter, Pos

Defined Under Namespace

Modules: HashKeys

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HashKeys

#eql?, #hash

Constructor Details

#initialize(id = 0) ⇒ ConstAttribute

Returns a new instance of ConstAttribute.

Raises:



30
31
32
33
34
# File 'lib/locomotive/relational_algebra/attributes.rb', line 30

def initialize(id=0)
  raise AbstractClassError,
        "#{self.class} is an abstract class" if self.class == ConstAttribute
  self.id = id
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



28
29
30
# File 'lib/locomotive/relational_algebra/attributes.rb', line 28

def id
  @id
end

Instance Method Details

#==(other) ⇒ Object

Equality for attributes is defined over their class and id



48
49
50
51
# File 'lib/locomotive/relational_algebra/attributes.rb', line 48

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

#cloneObject



71
72
73
74
# File 'lib/locomotive/relational_algebra/attributes.rb', line 71

def clone
  # an attributes contains only an id
  self.class.new(id)
end

#inc(val = 1) ⇒ Object



37
38
39
# File 'lib/locomotive/relational_algebra/attributes.rb', line 37

def inc(val=1)
  self.class.new(self.id + val)
end

#inspectObject



76
77
78
# File 'lib/locomotive/relational_algebra/attributes.rb', line 76

def inspect
  "<#{self.class.to_s.split('::').last} #{id}>"
end

#to_xmlObject



41
42
43
44
# File 'lib/locomotive/relational_algebra/attributes.rb', line 41

def to_xml
  # Be careful of classes that are nested in modules
  "#{self.class.to_s.split("::").last.downcase}#{nth id}".to_sym
end