Sha256: 2cc4977f528852ce7a48343e667ea32c2b20e4945fc22ba92ebe715d4b31eb55

Contents?: true

Size: 1.44 KB

Versions: 2

Compression:

Stored size: 1.44 KB

Contents

# encoding: utf-8

module Axiom
  class Function
    class Predicate

      # A mixin for predicates matching an enumerable
      module Enumerable

        # Return the method to test the enumerable with
        #
        # @param [#cover?, #include?] enumerable
        #
        # @return [Symbol]
        #
        # @api private
        def self.compare_method(enumerable)
          enumerable.respond_to?(:cover?) ? :cover? : :include?
        end

        # Initialize an Enumerable predicate
        #
        # @param [Object] left
        #   the attribute or object to test for in the Enumerable
        # @param [Enumerable] right
        #   the enumerable to test
        #
        # @return [undefined]
        #
        # @api private
        def initialize(left, right)
          super(left, freeze_object(right))
        end

        # Evaluate the enumerable function using the tuple
        #
        # @example
        #   enumerable.call(tuple)  # => true or false
        #
        # @param [Tuple] tuple
        #   the tuple to pass to #call in the left and right operands
        #
        # @return [Boolean]
        #
        # @api public
        def call(tuple)
          util = self.class
          util.call(
            util.extract_value(left, tuple),
            right.map { |entry| util.extract_value(entry, tuple) }
          )
        end

      end # module Enumerable
    end # class Predicate
  end # class Function
end # module Axiom

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
axiom-0.1.1 lib/axiom/function/predicate/enumerable.rb
axiom-0.1.0 lib/axiom/function/predicate/enumerable.rb