Sha256: 40b21c36257d2c01c19b01187026d2caacd0a218d0d4b1b60a743219cd1e9fed

Contents?: true

Size: 1.72 KB

Versions: 2

Compression:

Stored size: 1.72 KB

Contents

# encoding: utf-8

module Veritas
  module Logic
    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 [Expression] other
          #
          # @return [Inclusion]
          #
          # @api public
          def include(other)
            Inclusion.new(self, other)
          end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
veritas-0.0.3 lib/veritas/logic/predicate/inclusion.rb
veritas-0.0.2 lib/veritas/logic/predicate/inclusion.rb