Sha256: f53e1b6ada2ed2257d2ae9b64683d91f87106361f16fb83ded39a63b5944ddb2

Contents?: true

Size: 884 Bytes

Versions: 30

Compression:

Stored size: 884 Bytes

Contents

module Bmg
  module Operator
    #
    # Restrict operator.
    #
    # Filters operand's tuples to those that meet the predicate received
    # at construction.
    #
    class Restrict
      include Operator::Unary

      def initialize(type, operand, predicate)
        @type = type
        @operand = operand
        @predicate = predicate
      end

    protected

      attr_reader :predicate

    public

      def each
        @operand.each do |tuple|
          yield(tuple) if @predicate.evaluate(tuple)
        end
      end

      def to_ast
        [ :restrict, operand.to_ast, predicate.sexpr ]
      end

    protected

      def _restrict(type, predicate)
        Restrict.new(type, @operand, @predicate & predicate)
      end

    protected ### inspect

      def args
        [ predicate ]
      end

    end # class Restrict
  end # module Operator
end # module Bmg

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
bmg-0.16.7 lib/bmg/operator/restrict.rb
bmg-0.16.6 lib/bmg/operator/restrict.rb
bmg-0.16.5 lib/bmg/operator/restrict.rb
bmg-0.16.4 lib/bmg/operator/restrict.rb
bmg-0.16.3 lib/bmg/operator/restrict.rb
bmg-0.16.2 lib/bmg/operator/restrict.rb
bmg-0.16.1 lib/bmg/operator/restrict.rb
bmg-0.16.0 lib/bmg/operator/restrict.rb
bmg-0.16.0.pre.rc2 lib/bmg/operator/restrict.rb
bmg-0.16.0.pre.rc1 lib/bmg/operator/restrict.rb
bmg-0.15.0 lib/bmg/operator/restrict.rb
bmg-0.14.6 lib/bmg/operator/restrict.rb
bmg-0.14.5 lib/bmg/operator/restrict.rb
bmg-0.14.4 lib/bmg/operator/restrict.rb
bmg-0.14.3 lib/bmg/operator/restrict.rb
bmg-0.14.2 lib/bmg/operator/restrict.rb
bmg-0.14.1 lib/bmg/operator/restrict.rb
bmg-0.14.0 lib/bmg/operator/restrict.rb
bmg-0.13.0 lib/bmg/operator/restrict.rb
bmg-0.12.0 lib/bmg/operator/restrict.rb