Module: Alf::Lang::ObjectOriented::AlgebraMethods

Included in:
Alf::Lang::ObjectOriented
Defined in:
lib/alf-lang/alf/lang/oo/algebra_methods.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.def_operator_method(name, clazz) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/alf-lang/alf/lang/oo/algebra_methods.rb', line 6

def self.def_operator_method(name, clazz)
  define_method(name) do |*args|
    # add self operands at begining of args
    args.unshift(_self_operand)

    # split operands vs. arguments
    operands, arguments = args[0...clazz.arity], args[clazz.arity..-1]

    # build the new expression
    expr = clazz.new(operands, *arguments)

    # bind it if operands were bound
    conns = operands.map(&:connection).uniq
    if conns.size == 1
      expr.connection = conns.first
    elsif conns.size > 1
      raise NotSupportedError, "Multiple connections unsupported"
    end

    # let the abstraction have a chance to of decorating it
    _operator_output(expr)
  end
end

Instance Method Details

#!~(other) ⇒ Object



59
60
61
# File 'lib/alf-lang/alf/lang/oo/algebra_methods.rb', line 59

def !~(other)
  not_matching(other)
end

#&(other) ⇒ Object



51
52
53
# File 'lib/alf-lang/alf/lang/oo/algebra_methods.rb', line 51

def &(other)
  intersect(other)
end

#*(other) ⇒ Object



47
48
49
# File 'lib/alf-lang/alf/lang/oo/algebra_methods.rb', line 47

def *(other)
  join(other)
end

#+(other) ⇒ Object Also known as: |



38
39
40
# File 'lib/alf-lang/alf/lang/oo/algebra_methods.rb', line 38

def +(other)
  union(other)
end

#-(other) ⇒ Object



43
44
45
# File 'lib/alf-lang/alf/lang/oo/algebra_methods.rb', line 43

def -(other)
  minus(other)
end

#=~(other) ⇒ Object



55
56
57
# File 'lib/alf-lang/alf/lang/oo/algebra_methods.rb', line 55

def =~(other)
  matching(other)
end

#allbut(attributes) ⇒ Object



34
35
36
# File 'lib/alf-lang/alf/lang/oo/algebra_methods.rb', line 34

def allbut(attributes)
  project(attributes, :allbut => true)
end

#tuple_extractObject Also known as: tuple!

Raises:



63
64
65
66
67
68
69
70
71
72
# File 'lib/alf-lang/alf/lang/oo/algebra_methods.rb', line 63

def tuple_extract
  tuple = nil
  each do |t|
    raise NoSuchTupleError if tuple
    tuple = t
  end
  tuple ||= yield if block_given?
  raise NoSuchTupleError unless tuple or block_given?
  Tuple(tuple)
end