Class: Alf::Algebra::Operand::Named

Inherits:
Object
  • Object
show all
Includes:
Alf::Algebra::Operand
Defined in:
lib/alf/algebra/operand/named.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Alf::Algebra::Operand

#attr_list, coerce, #resulting_type, #to_ascii_tree, #to_relation

Constructor Details

#initialize(name, connection = nil) ⇒ Named

Returns a new instance of Named


7
8
9
10
# File 'lib/alf/algebra/operand/named.rb', line 7

def initialize(name, connection = nil)
  @name = name
  @connection = connection
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection


11
12
13
# File 'lib/alf/algebra/operand/named.rb', line 11

def connection
  @connection
end

#nameObject (readonly)

Returns the value of attribute name


11
12
13
# File 'lib/alf/algebra/operand/named.rb', line 11

def name
  @name
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?


35
36
37
38
39
# File 'lib/alf/algebra/operand/named.rb', line 35

def ==(other)
  super || (other.is_a?(Named) &&
            other.name==name   &&
            other.connection == connection)
end

#connection!Object

Raises:


13
14
15
16
# File 'lib/alf/algebra/operand/named.rb', line 13

def connection!
  raise UnboundError, "Expression not bound `#{name}`" unless connection
  connection
end

#hashObject


31
32
33
# File 'lib/alf/algebra/operand/named.rb', line 31

def hash
  @hash ||= name.hash + 37*connection.hash
end

#headingObject


27
28
29
# File 'lib/alf/algebra/operand/named.rb', line 27

def heading
  connection!.heading(name)
end

#inspectObject


54
55
56
# File 'lib/alf/algebra/operand/named.rb', line 54

def inspect
  "Operand::Named(#{name.inspect})"
end

#keysObject


23
24
25
# File 'lib/alf/algebra/operand/named.rb', line 23

def keys
  connection!.keys(name)
end

#to_cog(plan = Alf::Compiler::Plan.new) ⇒ Object


42
43
44
# File 'lib/alf/algebra/operand/named.rb', line 42

def to_cog(plan = Alf::Compiler::Plan.new)
  connection!.cog(plan, self)
end

#to_lispyObject


58
59
60
# File 'lib/alf/algebra/operand/named.rb', line 58

def to_lispy
  name.to_s
end

#to_relvarObject


46
47
48
# File 'lib/alf/algebra/operand/named.rb', line 46

def to_relvar
  Relvar::Base.new(self)
end

#to_sObject


50
51
52
# File 'lib/alf/algebra/operand/named.rb', line 50

def to_s
  name.to_s
end

#type_check(options = {strict: false}) ⇒ Object

Raises:


18
19
20
21
# File 'lib/alf/algebra/operand/named.rb', line 18

def type_check(options = {strict: false})
  return heading if connection!.knows?(name)
  raise TypeCheckError, "No such relvar `#{name}`"
end