Module: Bmg::Algebra::Shortcuts
- Included in:
- Bmg::Algebra
- Defined in:
- lib/bmg/algebra/shortcuts.rb
Instance Method Summary collapse
- #image(right, as = :image, on = [], options = {}) ⇒ Object
- #join(right, on = []) ⇒ Object
- #left_join(right, on = [], *args) ⇒ Object
- #matching(right, on = []) ⇒ Object
- #not_matching(right, on = []) ⇒ Object
- #prefix(prefix, options = {}) ⇒ Object
- #rxmatch(attrs, matcher, options = {}) ⇒ Object
- #suffix(suffix, options = {}) ⇒ Object
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 = [], = {}) return super unless on.is_a?(Hash) renaming = Hash[on.map{|k,v| [v,k] }] self.image(right.rename(renaming), as, on.keys, ) 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, = {}) raise "Attrlist must be known to use `prefix`" unless self.type.knows_attrlist? attrs = self.type.to_attrlist attrs = attrs - [:but] if [: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, = {}) predicate = attrs.inject(Predicate.contradiction){|p,a| p | Predicate.match(a, matcher, ) } 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, = {}) raise "Attrlist must be known to use `suffix`" unless self.type.knows_attrlist? attrs = self.type.to_attrlist attrs = attrs - [:but] if [:but] renaming = Hash[attrs.map{|a| [a, :"#{a}#{suffix}"] }] self.rename(renaming) end |