Sha256: 01f638bc08bd22688ab7a2c5e0b538dd894a6f2145815064b2e7263d5c2c0690

Contents?: true

Size: 700 Bytes

Versions: 2

Compression:

Stored size: 700 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_types
        [::Numeric]
      end

      def valid?(value)
        super &&
          !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

2 entries across 2 versions & 1 rubygems

Version Path
rice_bubble-0.2.1 lib/rice_bubble/attributes/number.rb
rice_bubble-0.2.0 lib/rice_bubble/attributes/number.rb