Sha256: 831bf0a810221ac9e74288b753f38676150ae82a69b16fff72e68e684616d4b7

Contents?: true

Size: 589 Bytes

Versions: 3

Compression:

Stored size: 589 Bytes

Contents

module Flipper
  module Types
    class Percentage < Type

      def self.wrap(value)
        return value if value.is_a?(self)
        new(value)
      end

      attr_reader :value

      def initialize(value)
        value = Typecast.to_integer(value)

        if value < 0 || value > 100
          raise ArgumentError, "value must be a positive number less than or equal to 100, but was #{value}"
        end

        @value = value
      end

      def eql?(other)
        self.class.eql?(other.class) && value == other.value
      end
      alias_method :==, :eql?
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
flipper-0.7.0.beta3 lib/flipper/types/percentage.rb
flipper-0.7.0.beta2 lib/flipper/types/percentage.rb
flipper-0.7.0.beta1 lib/flipper/types/percentage.rb