Class: CashRegister::NormalItem

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/cash_register/normal_item.rb

Direct Known Subclasses

DiscountItem, FreeItem, Two4OneItem

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper

#format_price

Constructor Details

#initialize(deal, count) ⇒ NormalItem

Returns a new instance of NormalItem.



9
10
11
12
# File 'lib/cash_register/normal_item.rb', line 9

def initialize(deal, count)
  @deal = deal
  @count = count
end

Instance Attribute Details

#countObject

Returns the value of attribute count.



7
8
9
# File 'lib/cash_register/normal_item.rb', line 7

def count
  @count
end

#dealObject

Returns the value of attribute deal.



7
8
9
# File 'lib/cash_register/normal_item.rb', line 7

def deal
  @deal
end

Instance Method Details

#billingObject



14
15
16
# File 'lib/cash_register/normal_item.rb', line 14

def billing
  @billing ||= deal.price * count
end

#savingObject



18
19
20
# File 'lib/cash_register/normal_item.rb', line 18

def saving
  0
end

#to_sObject



22
23
24
# File 'lib/cash_register/normal_item.rb', line 22

def to_s
  "名称:#{deal.name},数量:#{count}#{deal.unit},单价:#{format_price deal.price}(元),小计:#{format_price billing}(元)"
end