Sha256: 900c514bca2994bbbb0cf9f8dccb954643a1cadb1947a9ac33f039e9d07137b3

Contents?: true

Size: 1.72 KB

Versions: 4

Compression:

Stored size: 1.72 KB

Contents

# encoding: utf-8

module Veritas
  class Function
    class Predicate

      # A predicate representing an inclusion test
      class Inclusion < Predicate
        include Enumerable

        # Test an enumerable to see if a value is included
        #
        # @example
        #   Inclusion.call(1, [ 1, 2, 3 ])  # => true
        #
        # @param [Object] left
        #   the object to test for in the Enumerable
        # @param [Enumerable] right
        #   the enumerable to test
        #
        # @return [Boolean]
        #
        # @api public
        def self.call(left, right)
          right.send(Enumerable.compare_method(right), left)
        end

        # Return the inverse predicate class
        #
        # @example
        #   Inclusion.inverse  # => Exclusion
        #
        # @return [Class<Exclusion>]
        #
        # @api public
        def self.inverse
          Exclusion
        end

        # Return a string representing the predicate
        #
        # @example
        #   inclusion.inspect  # => "<Attribute::Integer name: id> ∈ [1, 2, 3]"
        #
        # @return [String]
        #
        # @api public
        def inspect
          "(#{left.inspect} ∈ #{right.inspect})"
        end

        module Methods

          # Compare the left to see if it is included in the right
          #
          # @example
          #   inclusion = attribute.include([ 1, 2, 3 ])
          #
          # @param [Function] other
          #
          # @return [Inclusion]
          #
          # @api public
          def include(other)
            Inclusion.new(self, other)
          end

        end # module Methods
      end # class Inclusion
    end # class Predicate
  end # class Function
end # module Veritas

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
veritas-0.0.7 lib/veritas/function/predicate/inclusion.rb
veritas-0.0.6 lib/veritas/function/predicate/inclusion.rb
veritas-0.0.5 lib/veritas/function/predicate/inclusion.rb
veritas-0.0.4 lib/veritas/function/predicate/inclusion.rb