Class: Fitting::Statistics::Percent
- Inherits:
-
Object
- Object
- Fitting::Statistics::Percent
- Defined in:
- lib/fitting/statistics/percent.rb
Instance Method Summary collapse
-
#initialize(divider, dividend) ⇒ Percent
constructor
A new instance of Percent.
- #to_f ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(divider, dividend) ⇒ Percent
Returns a new instance of Percent.
4 5 6 7 |
# File 'lib/fitting/statistics/percent.rb', line 4 def initialize(divider, dividend) @divider = divider @dividend = dividend end |
Instance Method Details
#to_f ⇒ Object
9 10 11 12 |
# File 'lib/fitting/statistics/percent.rb', line 9 def to_f return 0.to_f if @divider.zero? (@dividend.to_f / @divider.to_f * 100.0).round(2) end |
#to_s ⇒ Object
14 15 16 |
# File 'lib/fitting/statistics/percent.rb', line 14 def to_s "#{@dividend} (#{to_f}% of #{@divider})" end |