Class: Percentage
- Inherits:
-
Object
- Object
- Percentage
- Includes:
- Comparable
- Defined in:
- lib/chance/percentage.rb
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #*(other) ⇒ Object
- #<=>(other) ⇒ Object
- #chance ⇒ Object
-
#initialize(value) ⇒ Percentage
constructor
A new instance of Percentage.
- #of(number_or_percentage) ⇒ Object
- #to_f ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(value) ⇒ Percentage
Returns a new instance of Percentage.
6 7 8 |
# File 'lib/chance/percentage.rb', line 6 def initialize(value) @value = value end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
4 5 6 |
# File 'lib/chance/percentage.rb', line 4 def value @value end |
Instance Method Details
#*(other) ⇒ Object
30 31 32 33 |
# File 'lib/chance/percentage.rb', line 30 def *(other) other_value = other.kind_of?(Numeric) ? other : other.value Percentage.new value * other_value end |
#<=>(other) ⇒ Object
26 27 28 |
# File 'lib/chance/percentage.rb', line 26 def <=>(other) value <=> other.value end |
#of(number_or_percentage) ⇒ Object
10 11 12 |
# File 'lib/chance/percentage.rb', line 10 def of(number_or_percentage) number_or_percentage * (value / 100.0) end |
#to_f ⇒ Object
18 19 20 |
# File 'lib/chance/percentage.rb', line 18 def to_f @value.to_f end |
#to_s ⇒ Object
22 23 24 |
# File 'lib/chance/percentage.rb', line 22 def to_s to_f.to_s end |