class Switches::Percentage

Constants

LOWER
UPPER

Attributes

value[R]

Public Class Methods

new(value) click to toggle source
# File lib/switches/percentage.rb, line 11
def initialize(value)
  @value = clip(value.to_i)
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/switches/percentage.rb, line 15
def <=>(other)
  @value <=> other.value
end
include?(identifier) click to toggle source
# File lib/switches/percentage.rb, line 19
def include?(identifier)
  Percentage(Zlib.crc32(identifier.to_s) % UPPER) < self
end
inspect() click to toggle source
# File lib/switches/percentage.rb, line 35
def inspect
  to_s
end
max?() click to toggle source
# File lib/switches/percentage.rb, line 43
def max?
  @value == UPPER
end
min?() click to toggle source
# File lib/switches/percentage.rb, line 39
def min?
  @value == LOWER
end
to_f() click to toggle source
# File lib/switches/percentage.rb, line 27
def to_f
  @value.to_f
end
to_i() click to toggle source
# File lib/switches/percentage.rb, line 23
def to_i
  @value.to_i
end
to_s() click to toggle source
# File lib/switches/percentage.rb, line 31
def to_s
  "#{@value}%"
end

Private Instance Methods

clip(value) click to toggle source
# File lib/switches/percentage.rb, line 49
def clip(value)
  [LOWER, value.to_i, UPPER].sort[1]
end