Class: Switches::Percentage
- Inherits:
-
Object
- Object
- Switches::Percentage
- Includes:
- Comparable
- Defined in:
- lib/switches/percentage.rb
Constant Summary collapse
- LOWER =
0.0
- UPPER =
100.0
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #include?(identifier) ⇒ Boolean
-
#initialize(value) ⇒ Percentage
constructor
A new instance of Percentage.
- #inspect ⇒ Object
- #max? ⇒ Boolean
- #min? ⇒ Boolean
- #to_f ⇒ Object
- #to_i ⇒ Object
- #to_s ⇒ Object
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
19 20 21 |
# File 'lib/switches/percentage.rb', line 19 def include?(identifier) Percentage(Zlib.crc32(identifier.to_s) % UPPER) < self end |
#inspect ⇒ Object
35 36 37 |
# File 'lib/switches/percentage.rb', line 35 def inspect to_s end |
#max? ⇒ Boolean
43 44 45 |
# File 'lib/switches/percentage.rb', line 43 def max? @value == UPPER end |
#min? ⇒ Boolean
39 40 41 |
# File 'lib/switches/percentage.rb', line 39 def min? @value == LOWER end |
#to_f ⇒ Object
27 28 29 |
# File 'lib/switches/percentage.rb', line 27 def to_f @value.to_f end |
#to_i ⇒ Object
23 24 25 |
# File 'lib/switches/percentage.rb', line 23 def to_i @value.to_i end |
#to_s ⇒ Object
31 32 33 |
# File 'lib/switches/percentage.rb', line 31 def to_s "#{@value}%" end |