Class: CashRegister::ListItem
- Inherits:
-
Object
- Object
- CashRegister::ListItem
- Defined in:
- lib/cash_register/list_item.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
Returns the value of attribute count.
-
#deal ⇒ Object
Returns the value of attribute deal.
-
#free_item ⇒ Object
readonly
Returns the value of attribute free_item.
-
#item ⇒ Object
readonly
Returns the value of attribute item.
Instance Method Summary collapse
-
#initialize(code, count) ⇒ ListItem
constructor
A new instance of ListItem.
- #to_s ⇒ Object
Constructor Details
#initialize(code, count) ⇒ ListItem
Returns a new instance of ListItem.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/cash_register/list_item.rb', line 7 def initialize(code, count) @deal = Deals.find_by_code(code) @count = count @item ||= if Promotions.is_two_for_one?(deal.code) free_num = count/3 @free_item = FreeItem.new(deal, free_num) Two4OneItem.new(deal, count) elsif Promotions.is_discount?(deal.code) DiscountItem.new(deal, count) else NormalItem.new(deal, count) end end |
Instance Attribute Details
#count ⇒ Object
Returns the value of attribute count.
4 5 6 |
# File 'lib/cash_register/list_item.rb', line 4 def count @count end |
#deal ⇒ Object
Returns the value of attribute deal.
4 5 6 |
# File 'lib/cash_register/list_item.rb', line 4 def deal @deal end |
#free_item ⇒ Object (readonly)
Returns the value of attribute free_item.
5 6 7 |
# File 'lib/cash_register/list_item.rb', line 5 def free_item @free_item end |
#item ⇒ Object (readonly)
Returns the value of attribute item.
5 6 7 |
# File 'lib/cash_register/list_item.rb', line 5 def item @item end |
Instance Method Details
#to_s ⇒ Object
21 22 23 |
# File 'lib/cash_register/list_item.rb', line 21 def to_s item.to_s end |