Class: Maths::Percentage
- Inherits:
-
BigDecimal
- Object
- BigDecimal
- Maths::Percentage
- Defined in:
- lib/maths/percentage.rb
Overview
Public: Represents a number that should be formatted as a percentage
Class Method Summary collapse
-
.build(numerator, denominator) ⇒ Object
Public: Builds out a fraction by the numerator and denominator.
-
.change(from, to) ⇒ Object
Public: Calculates the % change of from to to.
Class Method Details
.build(numerator, denominator) ⇒ Object
Public: Builds out a fraction by the numerator and denominator
7 8 9 10 11 |
# File 'lib/maths/percentage.rb', line 7 def self.build(numerator, denominator) numerator = BigDecimal.new(numerator.to_s) denominator = BigDecimal.new(denominator.to_s) Percentage.new(((numerator / denominator) * 100).to_s) end |
.change(from, to) ⇒ Object
Public: Calculates the % change of from to to
14 15 16 |
# File 'lib/maths/percentage.rb', line 14 def self.change(from, to) Percentage.new((((to / from) - 1) * 100).to_s) end |