Sha256: d189cc6f1249dfc2a5195ca17298372caae1d68ad1f5f3393cc4745a14d2d9f2

Contents?: true

Size: 1.73 KB

Versions: 13

Compression:

Stored size: 1.73 KB

Contents

module Bmg
  module Algebra
    module Shortcuts

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

      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

      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

      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

      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

      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

      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

    end # module Shortcuts
  end # module Algebra
end # module Bmg

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
bmg-0.17.3 lib/bmg/algebra/shortcuts.rb
bmg-0.17.2 lib/bmg/algebra/shortcuts.rb
bmg-0.16.7 lib/bmg/algebra/shortcuts.rb
bmg-0.17.1 lib/bmg/algebra/shortcuts.rb
bmg-0.17.0 lib/bmg/algebra/shortcuts.rb
bmg-0.16.6 lib/bmg/algebra/shortcuts.rb
bmg-0.16.5 lib/bmg/algebra/shortcuts.rb
bmg-0.16.4 lib/bmg/algebra/shortcuts.rb
bmg-0.16.3 lib/bmg/algebra/shortcuts.rb
bmg-0.16.2 lib/bmg/algebra/shortcuts.rb
bmg-0.16.1 lib/bmg/algebra/shortcuts.rb
bmg-0.16.0 lib/bmg/algebra/shortcuts.rb
bmg-0.16.0.pre.rc2 lib/bmg/algebra/shortcuts.rb