Module: Bmg::Algebra::Shortcuts

Included in:
Bmg::Algebra
Defined in:
lib/bmg/algebra/shortcuts.rb

Instance Method Summary collapse

Instance Method Details

#cross_product(right) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/bmg/algebra/shortcuts.rb', line 60

def cross_product(right)
  return join(right) unless self.type.typechecked? || right.type.typechecked?
  return join(right) unless self.type.knows_attrlist? && right.type.knows_attrlist?

  self.type.cross_join_compatible!(right)
  return join(right)
end

#exclude(predicate) ⇒ Object



9
10
11
# File 'lib/bmg/algebra/shortcuts.rb', line 9

def exclude(predicate)
  restrict(!Predicate.coerce(predicate))
end

#image(right, as = :image, on = [], options = {}) ⇒ Object



36
37
38
39
40
# File 'lib/bmg/algebra/shortcuts.rb', line 36

def image(right, as = :image, on = [], options = {})
  return super unless on.is_a?(Hash)
  renaming = Hash[on.map{|k,v| [v,k] }]
  self.image(right.rename(renaming), as, on.keys, options)
end

#images(rights, on = [], options = {}) ⇒ Object



42
43
44
45
46
# File 'lib/bmg/algebra/shortcuts.rb', line 42

def images(rights, on = [], options = {})
  rights.each_pair.inject(self){|memo,(as,right)|
    memo.image(right, as, on, options)
  }
end

#join(right, on = []) ⇒ Object



48
49
50
51
52
# File 'lib/bmg/algebra/shortcuts.rb', line 48

def join(right, on = [])
  return super unless on.is_a?(Hash)
  renaming = Hash[on.map{|k,v| [v,k] }]
  self.join(right.rename(renaming), on.keys)
end

#left_join(right, on = [], *args) ⇒ Object



54
55
56
57
58
# File 'lib/bmg/algebra/shortcuts.rb', line 54

def left_join(right, on = [], *args)
  return super unless on.is_a?(Hash)
  renaming = Hash[on.map{|k,v| [v,k] }]
  self.left_join(right.rename(renaming), on.keys, *args)
end

#matching(right, on = []) ⇒ Object



68
69
70
71
72
# File 'lib/bmg/algebra/shortcuts.rb', line 68

def matching(right, on = [])
  return super unless on.is_a?(Hash)
  renaming = Hash[on.map{|k,v| [v,k] }]
  self.matching(right.rename(renaming), on.keys)
end

#not_matching(right, on = []) ⇒ Object



74
75
76
77
78
# File 'lib/bmg/algebra/shortcuts.rb', line 74

def not_matching(right, on = [])
  return super unless on.is_a?(Hash)
  renaming = Hash[on.map{|k,v| [v,k] }]
  self.not_matching(right.rename(renaming), on.keys)
end

#prefix(prefix, options = {}) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/bmg/algebra/shortcuts.rb', line 20

def prefix(prefix, options = {})
  raise "Attrlist must be known to use `prefix`" unless self.type.knows_attrlist?
  attrs = self.type.to_attrlist
  attrs = attrs - options[:but] if options[:but]
  renaming = Hash[attrs.map{|a| [a, :"#{prefix}#{a}"] }]
  self.rename(renaming)
end

#rxmatch(attrs, matcher, options = {}) ⇒ Object



13
14
15
16
17
18
# File 'lib/bmg/algebra/shortcuts.rb', line 13

def rxmatch(attrs, matcher, options = {})
  predicate = attrs.inject(Predicate.contradiction){|p,a|
    p | Predicate.match(a, matcher, options)
  }
  self.restrict(predicate)
end

#suffix(suffix, options = {}) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/bmg/algebra/shortcuts.rb', line 28

def suffix(suffix, options = {})
  raise "Attrlist must be known to use `suffix`" unless self.type.knows_attrlist?
  attrs = self.type.to_attrlist
  attrs = attrs - options[:but] if options[:but]
  renaming = Hash[attrs.map{|a| [a, :"#{a}#{suffix}"] }]
  self.rename(renaming)
end

#ungroup(attr) ⇒ Object



80
81
82
# File 'lib/bmg/algebra/shortcuts.rb', line 80

def ungroup(attr)
  super(attr.is_a?(Symbol) ? [attr] : attr)
end

#unwrap(attr) ⇒ Object



84
85
86
# File 'lib/bmg/algebra/shortcuts.rb', line 84

def unwrap(attr)
  super(attr.is_a?(Symbol) ? [attr] : attr)
end

#where(predicate) ⇒ Object



5
6
7
# File 'lib/bmg/algebra/shortcuts.rb', line 5

def where(predicate)
  restrict(predicate)
end