Class: Panier::Domain::Receipt

Inherits:
Object
  • Object
show all
Defined in:
lib/panier/domain/receipt.rb

Overview

A receipt is a value object describing a payment that has been made by a shopper to a merchant in relation to an order.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line_items) ⇒ Receipt

Initializes the receipt with the given line items.

Parameters:

  • line_items (Array)

    The line items to be represented on the receipt.



17
18
19
# File 'lib/panier/domain/receipt.rb', line 17

def initialize(line_items)
  @line_items = line_items
end

Instance Attribute Details

#line_itemsObject (readonly)

Returns the value of attribute line_items.



10
11
12
# File 'lib/panier/domain/receipt.rb', line 10

def line_items
  @line_items
end

Instance Method Details

#total_amountMoney

Calculates the total value of the receipt by adding together the total values of all line items.

Returns:

  • (Money)

    The total value of the receipt.



26
27
28
# File 'lib/panier/domain/receipt.rb', line 26

def total_amount
  line_items.reduce(Money.zero) { |a, e| a + e.total_amount_inc_tax }
end

#total_taxMoney

Calculates the total tax present on the receipt by adding together the total tax of all line items.

Returns:

  • (Money)

    The total tax present on the receipt.



35
36
37
# File 'lib/panier/domain/receipt.rb', line 35

def total_tax
  line_items.reduce(Money.zero) { |a, e| a + e.total_tax }
end