Class: SimpleMarketplace::Checkout
- Inherits:
-
Object
- Object
- SimpleMarketplace::Checkout
- Defined in:
- lib/simple_marketplace/checkout.rb
Instance Method Summary collapse
-
#clear_items ⇒ Object
Restart the cart.
-
#initialize(*promotional_rules) ⇒ Checkout
constructor
A new instance of Checkout.
-
#pretty_total ⇒ Object
Shows the formated total.
-
#scan(product_code) ⇒ Object
Adds an item to the cart.
-
#total ⇒ Object
Calculates the total with promotions applied.
Constructor Details
#initialize(*promotional_rules) ⇒ Checkout
Returns a new instance of Checkout.
4 5 6 7 |
# File 'lib/simple_marketplace/checkout.rb', line 4 def initialize(*promotional_rules) @promotional_rules = promotional_rules @items = [] end |
Instance Method Details
#clear_items ⇒ Object
Restart the cart
29 30 31 |
# File 'lib/simple_marketplace/checkout.rb', line 29 def clear_items @items = [] end |
#pretty_total ⇒ Object
Shows the formated total
24 25 26 |
# File 'lib/simple_marketplace/checkout.rb', line 24 def pretty_total "£#{'%.2f' % total}" end |
#scan(product_code) ⇒ Object
Adds an item to the cart
10 11 12 13 14 |
# File 'lib/simple_marketplace/checkout.rb', line 10 def scan(product_code) if (product = Product.get_by_code(product_code)) @items << product end end |
#total ⇒ Object
Calculates the total with promotions applied
17 18 19 20 21 |
# File 'lib/simple_marketplace/checkout.rb', line 17 def total @total = @items.map(&:price).reduce(:+) apply_promotional_rules @total end |