vending_machine 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ebf3a4903d76e77dcd088bb50901d2825b2d929d8d7122becf02a7b8deb0046a
4
- data.tar.gz: 3e0783031e9948ffd099f369a4bcff468c49a7d12cc7da4d1a239a2c9ee1a03d
3
+ metadata.gz: '08a9750307c60476f6c4e68a1f2edf9800d0c944791e1e5c2dd1157d1a8c3fe6'
4
+ data.tar.gz: c03495d5304e6cff454a8a45aaf011c669db8113ab1653489af1fd1455829577
5
5
  SHA512:
6
- metadata.gz: 15cd46d98aec5c7984ada2c49f69e6495e1ec973dbd87228d077ddf64d575f5a4d94d6d50796b3ea42a613d03f3d90619e039717403e2cb35b8f6f60deba5791
7
- data.tar.gz: 0a49e14a162353a7fc72ea3dcfe6d6b8e98eadbee87ffa2b98eb3a54036ea6e6bcb2cf2e6e21b58a89ad28baafd9b7ebf26df612a51cd5cb61bee7d7f24d674a
6
+ metadata.gz: d80412d3e605d85c44d786be06ed3db144d4d234fafe85cbd775fd9157896ee89cd79a542a496e996d58f00143f9a7545934365ddb2719c4b76d57ca795739f7
7
+ data.tar.gz: ec5810e1e15681af351b79ff6bdd5542ee1b7349c4ef81ad919f3487314ad70b60210cc12457870c78db5b068effc98ca7a568fb05c23bf2184ff978aefb8996
data/README.md CHANGED
@@ -99,7 +99,7 @@ machine.select_product(product: "Snickers", coins: ["€2"])
99
99
  ### Running the machine locally
100
100
  Simply run `gem install vending_machine`.
101
101
 
102
- Then call a CLI of your choice (for example `pry` or `irb`)
102
+ Then call a Ruby console of your choice (for example `pry` or `irb`)
103
103
 
104
104
  Requiring the installed gem will then let you interact with it.
105
105
 
@@ -117,4 +117,4 @@ This machine comes preloaded with some change and products for testing.
117
117
  ```
118
118
 
119
119
  ### Tests
120
- To run the tests simply `cd` into the root of the directory and run `rake`
120
+ To run the tests simply `cd` into the root of the directory and run `rake`
@@ -35,11 +35,12 @@ class Machine
35
35
  private def find_product(product:, cash_values:)
36
36
  product_price = product.cash_value
37
37
  if correct_change_given?(product_price: product_price, coins: cash_values)
38
- available_change[product_price] += 1
38
+ increment_available_change(cash_values)
39
39
  decrement_available_products(product)
40
40
  return product_and_change(product)
41
41
  end
42
42
  raise OutOfMoneyError if remaining_change.empty?
43
+ increment_available_change(cash_values)
43
44
  change = change(product_price: product_price, coins: cash_values)
44
45
  coins = calculate_coin_denominations(change: change)
45
46
  decrement_available_products(product)
@@ -55,9 +56,7 @@ class Machine
55
56
 
56
57
  private def correct_change_given?(product_price:, coins: [])
57
58
  raise ArgumentError unless coins.is_a? Array
58
- return true if exact_change?(coins: coins) && (product_price - coins.first).zero?
59
- change = change(product_price: product_price, coins: coins)
60
- change <= 0
59
+ true if exact_change?(coins: coins) && (product_price - coins.first).zero?
61
60
  end
62
61
 
63
62
  private def change(product_price:, coins:)
@@ -127,6 +126,10 @@ class Machine
127
126
  change_array.each { |change| available_change[change] -= 1 }
128
127
  end
129
128
 
129
+ private def increment_available_change(cash)
130
+ cash.each { |coin| available_change[coin] += 1 }
131
+ end
132
+
130
133
  private def decrement_available_products(product)
131
134
  products[product.name][:available] -= 1
132
135
  end
@@ -1,3 +1,3 @@
1
1
  module VendingMachine
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vending_machine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan O'Mahony