Class: Panier::Domain::RoundUpRounding
- Inherits:
-
Object
- Object
- Panier::Domain::RoundUpRounding
- Defined in:
- lib/panier/domain/round_up_rounding.rb
Overview
A money-rounding strategy that rounds fractional values up to the nearest increment. For example, $0.21 would be rounded up to $0.25.
Instance Method Summary collapse
-
#initialize(increment = 5) ⇒ RoundUpRounding
constructor
A new instance of RoundUpRounding.
-
#round(value) ⇒ Object
Rounds a monetary value up to the nearest increment.
Constructor Details
#initialize(increment = 5) ⇒ RoundUpRounding
Returns a new instance of RoundUpRounding.
14 15 16 |
# File 'lib/panier/domain/round_up_rounding.rb', line 14 def initialize(increment = 5) self.increment = increment end |
Instance Method Details
#round(value) ⇒ Object
Rounds a monetary value up to the nearest increment.
23 24 25 26 27 28 |
# File 'lib/panier/domain/round_up_rounding.rb', line 23 def round(value) unless value % @increment == Money.zero value += Money.new(@increment) - value % @increment end value end |