Class: Vvm::State::PositiveBalance
- Inherits:
-
Base
- Object
- Base
- Vvm::State::PositiveBalance
show all
- Defined in:
- lib/vvm/state/positive_balance.rb
Instance Method Summary
collapse
Methods inherited from Base
#dispense, #initialize
Instance Method Details
#insert(coin) ⇒ Object
6
7
8
9
|
# File 'lib/vvm/state/positive_balance.rb', line 6
def insert(coin)
machine.balance += coin
machine
end
|
#pick(product_name) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/vvm/state/positive_balance.rb', line 11
def pick(product_name)
product = machine.inventory.detect { _1.name == product_name }
validate(product)
machine.balance = (machine.balance - product.price).round(2)
product.qty -= 1
maybe_change_state
product
end
|