Class: Fitting::Statistics::Percent

Inherits:
Object
  • Object
show all
Defined in:
lib/fitting/statistics/percent.rb

Instance Method Summary collapse

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_fObject



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_sObject



14
15
16
# File 'lib/fitting/statistics/percent.rb', line 14

def to_s
  "#{@dividend} (#{to_f}% of #{@divider})"
end