Module: Bmg::Algebra::Shortcuts

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

Instance Method Summary collapse

Instance Method Details

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



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

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

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



34
35
36
37
38
# File 'lib/bmg/algebra/shortcuts.rb', line 34

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



40
41
42
43
44
# File 'lib/bmg/algebra/shortcuts.rb', line 40

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



46
47
48
49
50
# File 'lib/bmg/algebra/shortcuts.rb', line 46

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



52
53
54
55
56
# File 'lib/bmg/algebra/shortcuts.rb', line 52

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



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

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



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

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



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

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