Sha256: 5e9d4cfa6d35ccedf41dd079588c05717caa8766c063af1152ffe5061deceb7c

Contents?: true

Size: 895 Bytes

Versions: 3

Compression:

Stored size: 895 Bytes

Contents

# frozen_string_literal: true

require "key_vortex/constraint/base"

class KeyVortex
  module Constraint
    # Enforces that objects which respond to #>= are greater than the
    # defined limit.
    class Minimum < KeyVortex::Constraint::Base
      # @return [Integer] The minimum allowed value
      attr_reader :limit

      # @param limit [Integer] The minimum allowed value
      def initialize(limit)
        super()
        @limit = limit
      end

      # @return [Symbol] :minimum
      def attribute
        :minimum
      end

      # @param constraint [Minimum]
      # @return [Boolean] True if limit >= constraint.limit
      def within?(constraint)
        super && limit >= constraint.limit
      end

      # @param value [Object] Must respond to #>=
      # @return [Boolean] True if value >= limit
      def accepts?(value)
        value >= limit
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
key-vortex-1.1.1 lib/key_vortex/constraint/minimum.rb
key-vortex-1.1.0 lib/key_vortex/constraint/minimum.rb
key-vortex-1.0.0 lib/key_vortex/constraint/minimum.rb