Class: Switches::Percentage

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/switches/percentage.rb

Constant Summary collapse

LOWER =
0.0
UPPER =
100.0

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Percentage

Returns a new instance of Percentage.



11
12
13
# File 'lib/switches/percentage.rb', line 11

def initialize(value)
  @value = clip(value.to_i)
end

Instance Method Details

#<=>(other) ⇒ Object



15
16
17
# File 'lib/switches/percentage.rb', line 15

def <=>(other)
  @value <=> other.value
end

#include?(identifier) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/switches/percentage.rb', line 19

def include?(identifier)
  Percentage(Zlib.crc32(identifier.to_s) % UPPER) < self
end

#inspectObject



35
36
37
# File 'lib/switches/percentage.rb', line 35

def inspect
  to_s
end

#max?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/switches/percentage.rb', line 43

def max?
  @value == UPPER
end

#min?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/switches/percentage.rb', line 39

def min?
  @value == LOWER
end

#to_fObject



27
28
29
# File 'lib/switches/percentage.rb', line 27

def to_f
  @value.to_f
end

#to_iObject



23
24
25
# File 'lib/switches/percentage.rb', line 23

def to_i
  @value.to_i
end

#to_sObject



31
32
33
# File 'lib/switches/percentage.rb', line 31

def to_s
  "#{@value}%"
end