Sha256: 883fd0e54fdb69699d5285b9893603d1d8eba859fa58fd070bfaf9bcb5ea0582

Contents?: true

Size: 664 Bytes

Versions: 3

Compression:

Stored size: 664 Bytes

Contents

module RiceBubble
  class Attributes
    class Number < Base
      attr_reader :min, :max

      def initialize(min: nil, max: nil, &)
        super(&)
        @min = min
        @max = max
      end

      def valid?(value)
        value.is_a?(::Numeric) &&
          !min&.send(:>, value) &&
          !max&.send(:<, value)
      end

      def description
        result = super

        if min && max
          "#{result} between #{min} and #{max}"
        elsif min
          "#{result} greater than or equal to #{min}"
        elsif max
          "#{result} less than or equal to #{max}"
        else
          result
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rice_bubble-0.1.2 lib/rice_bubble/attributes/number.rb
rice_bubble-0.1.1 lib/rice_bubble/attributes/number.rb
rice_bubble-0.1.0 lib/rice_bubble/attributes/number.rb