Class: Panier::Domain::Receipt
- Inherits:
-
Object
- Object
- Panier::Domain::Receipt
- 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
-
#line_items ⇒ Object
readonly
Returns the value of attribute line_items.
Instance Method Summary collapse
-
#initialize(line_items) ⇒ Receipt
constructor
Initializes the receipt with the given line items.
-
#total_amount ⇒ Money
Calculates the total value of the receipt by adding together the total values of all line items.
-
#total_tax ⇒ Money
Calculates the total tax present on the receipt by adding together the total tax of all line items.
Constructor Details
#initialize(line_items) ⇒ Receipt
Initializes the receipt with the given line items.
17 18 19 |
# File 'lib/panier/domain/receipt.rb', line 17 def initialize(line_items) @line_items = line_items end |
Instance Attribute Details
#line_items ⇒ Object (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_amount ⇒ Money
Calculates the total value of the receipt by adding together the total values of all line items.
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_tax ⇒ Money
Calculates the total tax present on the receipt by adding together the total tax of all line items.
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 |