class Panier::Domain::RoundUpRounding
A money-rounding strategy that rounds fractional values up to the nearest increment. For example, $0.21 would be rounded up to $0.25.
Public Class Methods
new(increment = 5)
click to toggle source
@param increment [Integer] The fractional value to which rounding
calculations are made.
# File lib/panier/domain/round_up_rounding.rb, line 14 def initialize(increment = 5) self.increment = increment end
Public Instance Methods
round(value)
click to toggle source
Rounds a monetary value up to the nearest increment.
@param value [Money] The amount of tax to be rounded.
# 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
Private Instance Methods
increment=(increment)
click to toggle source
# File lib/panier/domain/round_up_rounding.rb, line 32 def increment=(increment) fail ArgumentError ':increment must be non-negative' if increment < 0 @increment = increment end