Class: Panier::Domain::RoundUpRounding

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(increment = 5) ⇒ RoundUpRounding

Returns a new instance of RoundUpRounding.

Parameters:

  • increment (Integer) (defaults to: 5)

    The fractional value to which rounding calculations are made.



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.

Parameters:

  • value (Money)

    The amount of tax to be rounded.



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