Sha256: 07639f15c638fa3c535f242121c1cbd46ae4087583e85da67b9fbbcb808c0dab

Contents?: true

Size: 918 Bytes

Versions: 5

Compression:

Stored size: 918 Bytes

Contents

module Alf
  module Engine
    #
    # Filters operand using a tuple predicate.
    #
    # Example
    #
    #     rel = [
    #       {:name => "Smith"},
    #       {:name => "Jones"}
    #     ]
    #     Filter.new(rel, TuplePredicate["name =~ /^J/"]).to_a
    #     # => [
    #     #      {:name => "Jones"}
    #     #    ]
    #
    class Filter < Cog

      # @return [Enumerable] The operand
      attr_reader :operand

      # @return [TuplePredicate] Filtering predicate
      attr_reader :predicate

      # Creates a Filter instance
      def initialize(operand, predicate)
        @operand = operand
        @predicate = predicate
      end

      # (see Cog#each)
      def each
        handle = Tools::TupleHandle.new
        operand.each do |tuple|
          yield(tuple) if @predicate.evaluate(handle.set(tuple))
        end
      end

    end # class Filter
  end # module Engine
end # module Alf

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
alf-0.12.2 lib/alf-engine/alf/engine/filter.rb
alf-0.12.1 lib/alf-engine/alf/engine/filter.rb
alf-0.12.0 lib/alf-engine/alf/engine/filter.rb
alf-0.11.1 lib/alf-engine/alf/engine/filter.rb
alf-0.11.0 lib/alf-engine/alf/engine/filter.rb