vending_machine 0.1.6
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 +7 -0
- data/.gitignore +9 -0
- data/.rspec +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +9 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +37 -0
- data/LICENSE.txt +21 -0
- data/README.md +120 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/errors/invalid_coin_error.rb +2 -0
- data/lib/errors/more_money_error.rb +2 -0
- data/lib/errors/no_money_error.rb +2 -0
- data/lib/errors/out_of_money_error.rb +2 -0
- data/lib/errors/out_of_selected_product_error.rb +2 -0
- data/lib/machine/cash.rb +51 -0
- data/lib/machine/machine.rb +133 -0
- data/lib/machine/product.rb +14 -0
- data/lib/vending_machine/version.rb +3 -0
- data/lib/vending_machine.rb +33 -0
- data/vending_machine.gemspec +29 -0
- metadata +108 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: ebf3a4903d76e77dcd088bb50901d2825b2d929d8d7122becf02a7b8deb0046a
|
|
4
|
+
data.tar.gz: 3e0783031e9948ffd099f369a4bcff468c49a7d12cc7da4d1a239a2c9ee1a03d
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 15cd46d98aec5c7984ada2c49f69e6495e1ec973dbd87228d077ddf64d575f5a4d94d6d50796b3ea42a613d03f3d90619e039717403e2cb35b8f6f60deba5791
|
|
7
|
+
data.tar.gz: 0a49e14a162353a7fc72ea3dcfe6d6b8e98eadbee87ffa2b98eb3a54036ea6e6bcb2cf2e6e21b58a89ad28baafd9b7ebf26df612a51cd5cb61bee7d7f24d674a
|
data/.gitignore
ADDED
data/.rspec
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--require spec_helper
|
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2.5.1
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
GEM
|
|
2
|
+
remote: https://rubygems.org/
|
|
3
|
+
specs:
|
|
4
|
+
coderay (1.1.2)
|
|
5
|
+
diff-lcs (1.3)
|
|
6
|
+
method_source (0.9.0)
|
|
7
|
+
pry (0.11.3)
|
|
8
|
+
coderay (~> 1.1.0)
|
|
9
|
+
method_source (~> 0.9.0)
|
|
10
|
+
rake (12.3.1)
|
|
11
|
+
rspec (3.8.0)
|
|
12
|
+
rspec-core (~> 3.8.0)
|
|
13
|
+
rspec-expectations (~> 3.8.0)
|
|
14
|
+
rspec-mocks (~> 3.8.0)
|
|
15
|
+
rspec-core (3.8.0)
|
|
16
|
+
rspec-support (~> 3.8.0)
|
|
17
|
+
rspec-expectations (3.8.1)
|
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
19
|
+
rspec-support (~> 3.8.0)
|
|
20
|
+
rspec-mocks (3.8.0)
|
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
22
|
+
rspec-support (~> 3.8.0)
|
|
23
|
+
rspec-support (3.8.0)
|
|
24
|
+
|
|
25
|
+
PLATFORMS
|
|
26
|
+
ruby
|
|
27
|
+
|
|
28
|
+
DEPENDENCIES
|
|
29
|
+
pry
|
|
30
|
+
rake
|
|
31
|
+
rspec
|
|
32
|
+
|
|
33
|
+
RUBY VERSION
|
|
34
|
+
ruby 2.5.1p57
|
|
35
|
+
|
|
36
|
+
BUNDLED WITH
|
|
37
|
+
1.16.3
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Jonathan O'Mahony
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# Vending Machine [](https://travis-ci.org/jonnyom/vending_machine)
|
|
2
|
+
This is a Ruby gem which emulates a vending machine.
|
|
3
|
+
|
|
4
|
+
Provided with the name of a product and an array of coins (in string values),
|
|
5
|
+
the machine will either return the correct product,
|
|
6
|
+
or inform you of the relevant error.
|
|
7
|
+
|
|
8
|
+
### Installing the machine
|
|
9
|
+
```
|
|
10
|
+
gem install vending_machine
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### The machine
|
|
14
|
+
The machine itself contains a hash of products, and its available change,
|
|
15
|
+
in denominations of €2 to 1c inclusive.
|
|
16
|
+
|
|
17
|
+
For example
|
|
18
|
+
```ruby
|
|
19
|
+
change = {
|
|
20
|
+
"1c" => 100,
|
|
21
|
+
"2c" => 100,
|
|
22
|
+
"5c" => 100,
|
|
23
|
+
"10c" => 100,
|
|
24
|
+
"20c" => 100,
|
|
25
|
+
"50c" => 100,
|
|
26
|
+
"€1" => 100,
|
|
27
|
+
"€2" => 100
|
|
28
|
+
}
|
|
29
|
+
snickers = Product.new(name: "Snickers", price: "€2")
|
|
30
|
+
mars_bar = Product.new(name: "Mars Bar", price: "€1")
|
|
31
|
+
products = {
|
|
32
|
+
"Snickers" => {
|
|
33
|
+
product: snickers,
|
|
34
|
+
available: 10
|
|
35
|
+
},
|
|
36
|
+
"mars bar" => {
|
|
37
|
+
product: mars_bar,
|
|
38
|
+
available: 5
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
machine = Machine.new(products: products, available_change: change)
|
|
42
|
+
|
|
43
|
+
machine.select_product(product: "Mars Bar", coins: ["20c", "50c", "10c", "20c"])
|
|
44
|
+
=> {:product=>"Mars Bar", :change=>["0"]}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
If not enough money is given, the machine raises a MoreMoneyError and exits
|
|
48
|
+
|
|
49
|
+
```ruby
|
|
50
|
+
machine.select_product(product: "Snickers", coins: ["20c", "50c", "10c", "20c"])
|
|
51
|
+
MoreMoneyError: MoreMoneyError
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The machine can be refilled with both products and change
|
|
55
|
+
```ruby
|
|
56
|
+
machine = Machine.new(products: [Product.new(name: "snickers", price: "€2")], available_change: available_change)
|
|
57
|
+
=> #<Machine:0x00007fb3ac086440 @available_change={1=>100, 2=>100, 5=>100, 10=>100, 20=>100, 50=>100, 100=>100, 200=>100}, @products=[#<Product:0x00007fb3ac0864e0 @name="snickers", @price="€2">]>
|
|
58
|
+
cash_refill = { "1c" => 100 }
|
|
59
|
+
machine.refill_cash(cash_refill)
|
|
60
|
+
=> {1=>100}
|
|
61
|
+
machine.available_change
|
|
62
|
+
=> {1=>200, 2=>100, 5=>100, 10=>100, 20=>100, 50=>100, 100=>100, 200=>100}
|
|
63
|
+
|
|
64
|
+
milky_bar = Product.new(name: "milky bar", price: "60c")
|
|
65
|
+
=> #<Product:0x00007fb81297fc30 @name="milky bar", @price="60c">
|
|
66
|
+
snickers = Product.new(name: "Snickers", price: "€2")
|
|
67
|
+
=> #<Product:0x00007fb8121e76a8 @name="Snickers", @price="€2">
|
|
68
|
+
machine.refill_products([{ product: milky_bar, available: 10 }, { product: snickers, available: 15 }])
|
|
69
|
+
=> [{:product=>#<Product:0x00007fb81297fc30 @name="milky bar", @price="60c">, :available=>10}, {:product=>#<Product:0x00007fb8121e76a8 @name="Snickers", @price="€2">, :available=>15}]
|
|
70
|
+
machine.products
|
|
71
|
+
=> {"Snickers"=>{:product=>#<Product:0x00007fb8121a54b0 @name="Snickers", @price="€2">, :available=>25},
|
|
72
|
+
"Mars Bar"=>{:product=>#<Product:0x00007fb8121a53e8 @name="Mars Bar", @price="€1">, :available=>5},
|
|
73
|
+
"milky bar"=>{:product=>#<Product:0x00007fb81297fc30 @name="milky bar", @price="60c">, :available=>20}}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### How does it find the correct change
|
|
77
|
+
The algorithm behind finding the correct change is a simple greedy algorithm which
|
|
78
|
+
constantly asks for the largest coin denomination that can be returned without
|
|
79
|
+
the change going below 0.
|
|
80
|
+
|
|
81
|
+
For example
|
|
82
|
+
```ruby
|
|
83
|
+
available_coins = [1, 3, 4], change = 2
|
|
84
|
+
2 - 4 = -2: less than 0, moving on
|
|
85
|
+
2 - 3 = -1: less than 0, moving on
|
|
86
|
+
2 - 1 = 1: greater than 0, adding 1 to change array and checking if 1 still works with new change of 1
|
|
87
|
+
1 - 1 = 0: greater than 0, adding 1 to change array and checking if 1 still works with new change of 0
|
|
88
|
+
0 - 1 = -1: less than 0, moving on and breaking out as we have come to the end of the array
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
If the exact change for a product's price is given and no change needs to be calculated,
|
|
92
|
+
the machine simply returns the product and 0 change.
|
|
93
|
+
|
|
94
|
+
```ruby
|
|
95
|
+
machine.select_product(product: "Snickers", coins: ["€2"])
|
|
96
|
+
=> {:product=>"Snickers", :change=>["0"]}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Running the machine locally
|
|
100
|
+
Simply run `gem install vending_machine`.
|
|
101
|
+
|
|
102
|
+
Then call a CLI of your choice (for example `pry` or `irb`)
|
|
103
|
+
|
|
104
|
+
Requiring the installed gem will then let you interact with it.
|
|
105
|
+
|
|
106
|
+
This machine comes preloaded with some change and products for testing.
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
~/vending_machine ❯❯❯ pry
|
|
111
|
+
[1] pry(main)> require "vending_machine"
|
|
112
|
+
=> true
|
|
113
|
+
[2] pry(main)> machine = Machine.new(products: products, available_change: change)
|
|
114
|
+
=> #<Machine:0x00007f8867a59280
|
|
115
|
+
@available_change={1=>100, 2=>100, 5=>100, 10=>100, 20=>100, 50=>100, 100=>100, 200=>100},
|
|
116
|
+
@products={"Snickers"=>{:product=>#<Product:0x00007f8867a59460 @name="Snickers", @price="€2">, :available=>10}, "Mars Bar"=>{:product=>#<Product:0x00007f8867a59398 @name="Mars Bar", @price="€1">, :available=>5}}>
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Tests
|
|
120
|
+
To run the tests simply `cd` into the root of the directory and run `rake`
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "vending_machine"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "pry"
|
|
14
|
+
Pry.start
|
data/bin/setup
ADDED
data/lib/machine/cash.rb
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
class Cash
|
|
2
|
+
|
|
3
|
+
class << self
|
|
4
|
+
def cash_values(coins)
|
|
5
|
+
coins.map { |coin| coin_map[coin] }
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def string_values(coins)
|
|
9
|
+
coins.map { |coin| to_string[coin] }
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def cash_value(coin)
|
|
13
|
+
coin_map[coin]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def string_value(coin)
|
|
17
|
+
to_string[coin]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def valid_coins
|
|
21
|
+
coin_map.keys
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private def coin_map
|
|
25
|
+
{
|
|
26
|
+
"1c" => 1,
|
|
27
|
+
"2c" => 2,
|
|
28
|
+
"5c" => 5,
|
|
29
|
+
"10c" => 10,
|
|
30
|
+
"20c" => 20,
|
|
31
|
+
"50c" => 50,
|
|
32
|
+
"€1" => 100,
|
|
33
|
+
"€2" => 200
|
|
34
|
+
}
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
private def to_string
|
|
38
|
+
{
|
|
39
|
+
1 => "1c",
|
|
40
|
+
2 => "2c",
|
|
41
|
+
5 => "5c",
|
|
42
|
+
10 => "10c",
|
|
43
|
+
20 => "20c",
|
|
44
|
+
50 => "50c",
|
|
45
|
+
100 => "€1",
|
|
46
|
+
200 => "€2"
|
|
47
|
+
}
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
end
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "./cash"
|
|
4
|
+
require_relative "./product"
|
|
5
|
+
require_relative "../errors/invalid_coin_error"
|
|
6
|
+
require_relative "../errors/more_money_error"
|
|
7
|
+
require_relative "../errors/no_money_error"
|
|
8
|
+
require_relative "../errors/out_of_money_error"
|
|
9
|
+
require_relative "../errors/out_of_selected_product_error"
|
|
10
|
+
|
|
11
|
+
class Machine
|
|
12
|
+
attr_accessor :products, :available_change
|
|
13
|
+
|
|
14
|
+
def initialize(products:, available_change:)
|
|
15
|
+
@products = products
|
|
16
|
+
@available_change = transform_keys_to_cash(available_change)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def select_product(product:, coins:)
|
|
20
|
+
raise ArgumentError unless coins.is_a? Array
|
|
21
|
+
raise NoMoneyError if coins.empty?
|
|
22
|
+
product = products[product]
|
|
23
|
+
raise OutOfSelectedProductError if product.nil? || product[:available].zero?
|
|
24
|
+
find_product(product: product[:product], cash_values: Cash.cash_values(coins))
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def refill_products(products)
|
|
28
|
+
reload_products(product_refills: products)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def refill_cash(cash)
|
|
32
|
+
reload_cash(cash_refills: cash)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private def find_product(product:, cash_values:)
|
|
36
|
+
product_price = product.cash_value
|
|
37
|
+
if correct_change_given?(product_price: product_price, coins: cash_values)
|
|
38
|
+
available_change[product_price] += 1
|
|
39
|
+
decrement_available_products(product)
|
|
40
|
+
return product_and_change(product)
|
|
41
|
+
end
|
|
42
|
+
raise OutOfMoneyError if remaining_change.empty?
|
|
43
|
+
change = change(product_price: product_price, coins: cash_values)
|
|
44
|
+
coins = calculate_coin_denominations(change: change)
|
|
45
|
+
decrement_available_products(product)
|
|
46
|
+
product_and_change(product, Cash.string_values(coins))
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
private def product_and_change(product, change = nil)
|
|
50
|
+
{
|
|
51
|
+
product: product.name,
|
|
52
|
+
change: change.nil? ? ["0"] : change
|
|
53
|
+
}
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
private def correct_change_given?(product_price:, coins: [])
|
|
57
|
+
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
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
private def change(product_price:, coins:)
|
|
64
|
+
@change ||= calculate_change(product_price: product_price, coins: coins)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
private def calculate_change(product_price:, coins:)
|
|
68
|
+
sorted_coins = coins.sort.reverse!
|
|
69
|
+
sorted_coins.each do |coin|
|
|
70
|
+
product_price -= coin
|
|
71
|
+
end
|
|
72
|
+
raise MoreMoneyError if product_price.positive?
|
|
73
|
+
product_price.abs
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
private def calculate_coin_denominations(change:)
|
|
77
|
+
available_coins = remaining_change.keys.sort.reverse!
|
|
78
|
+
change_array = []
|
|
79
|
+
available_coins.each do |coin|
|
|
80
|
+
next if (change - coin).negative?
|
|
81
|
+
until (change - coin).negative?
|
|
82
|
+
change -= coin
|
|
83
|
+
change_array << coin
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
decrement_available_change(change_array)
|
|
87
|
+
change_array
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
private def reload_products(product_refills:)
|
|
91
|
+
raise ArgumentError unless product_refills.is_a? Array
|
|
92
|
+
raise ArgumentError unless product_refills.all? { |product_refill| product_refill[:product].is_a? Product }
|
|
93
|
+
raise ArgumentError if product_refills.empty?
|
|
94
|
+
product_refills.each do |product_refill|
|
|
95
|
+
product_name = product_refill[:product].name
|
|
96
|
+
if products[product_name].nil?
|
|
97
|
+
products[product_name] = product_refill
|
|
98
|
+
else
|
|
99
|
+
products[product_name][:available] += product_refill[:available]
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
private def reload_cash(cash_refills:)
|
|
105
|
+
raise ArgumentError if cash_refills.empty?
|
|
106
|
+
raise InvalidCoinError unless (cash_refills.keys - Cash.valid_coins).empty?
|
|
107
|
+
cash_value_refills = transform_keys_to_cash(cash_refills)
|
|
108
|
+
cash_value_refills.each do |coin, amount|
|
|
109
|
+
next if amount.negative?
|
|
110
|
+
available_change[coin] += amount
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
private def exact_change?(coins:)
|
|
115
|
+
coins.length == 1
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
private def remaining_change
|
|
119
|
+
available_change.select { |coin, remaining| remaining.positive? }
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
private def transform_keys_to_cash(coins)
|
|
123
|
+
coins.transform_keys! { |coin| Cash.cash_value(coin) }
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
private def decrement_available_change(change_array)
|
|
127
|
+
change_array.each { |change| available_change[change] -= 1 }
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
private def decrement_available_products(product)
|
|
131
|
+
products[product.name][:available] -= 1
|
|
132
|
+
end
|
|
133
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require "machine/product"
|
|
2
|
+
require "machine/machine"
|
|
3
|
+
|
|
4
|
+
def products
|
|
5
|
+
snickers = Product.new(name: "Snickers", price: "€2")
|
|
6
|
+
mars_bar = Product.new(name: "Mars Bar", price: "€1")
|
|
7
|
+
{
|
|
8
|
+
"Snickers" => {
|
|
9
|
+
product: snickers,
|
|
10
|
+
available: 10
|
|
11
|
+
},
|
|
12
|
+
"Mars Bar" => {
|
|
13
|
+
product: mars_bar,
|
|
14
|
+
available: 5
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def change
|
|
20
|
+
{
|
|
21
|
+
"1c" => 100,
|
|
22
|
+
"2c" => 100,
|
|
23
|
+
"5c" => 100,
|
|
24
|
+
"10c" => 100,
|
|
25
|
+
"20c" => 100,
|
|
26
|
+
"50c" => 100,
|
|
27
|
+
"€1" => 100,
|
|
28
|
+
"€2" => 100
|
|
29
|
+
}
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
module VendingMachine
|
|
33
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require "vending_machine/version"
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "vending_machine"
|
|
8
|
+
spec.version = VendingMachine::VERSION
|
|
9
|
+
spec.authors = ["Jonathan O'Mahony"]
|
|
10
|
+
spec.email = ["jonathanomahony@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{Simple Vending Machine}
|
|
13
|
+
spec.description = %q{A simple vending machine in Ruby}
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.add_development_dependency "rspec", '~> 0'
|
|
17
|
+
|
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
20
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
22
|
+
end
|
|
23
|
+
spec.bindir = "exe"
|
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
25
|
+
spec.require_paths = ["lib"]
|
|
26
|
+
|
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
29
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: vending_machine
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.6
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Jonathan O'Mahony
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-10-13 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rspec
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: bundler
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '1.16'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.16'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rake
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '10.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '10.0'
|
|
55
|
+
description: A simple vending machine in Ruby
|
|
56
|
+
email:
|
|
57
|
+
- jonathanomahony@gmail.com
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- ".gitignore"
|
|
63
|
+
- ".rspec"
|
|
64
|
+
- ".ruby-version"
|
|
65
|
+
- ".travis.yml"
|
|
66
|
+
- Gemfile
|
|
67
|
+
- Gemfile.lock
|
|
68
|
+
- LICENSE.txt
|
|
69
|
+
- README.md
|
|
70
|
+
- Rakefile
|
|
71
|
+
- bin/console
|
|
72
|
+
- bin/setup
|
|
73
|
+
- lib/errors/invalid_coin_error.rb
|
|
74
|
+
- lib/errors/more_money_error.rb
|
|
75
|
+
- lib/errors/no_money_error.rb
|
|
76
|
+
- lib/errors/out_of_money_error.rb
|
|
77
|
+
- lib/errors/out_of_selected_product_error.rb
|
|
78
|
+
- lib/machine/cash.rb
|
|
79
|
+
- lib/machine/machine.rb
|
|
80
|
+
- lib/machine/product.rb
|
|
81
|
+
- lib/vending_machine.rb
|
|
82
|
+
- lib/vending_machine/version.rb
|
|
83
|
+
- vending_machine.gemspec
|
|
84
|
+
homepage:
|
|
85
|
+
licenses:
|
|
86
|
+
- MIT
|
|
87
|
+
metadata: {}
|
|
88
|
+
post_install_message:
|
|
89
|
+
rdoc_options: []
|
|
90
|
+
require_paths:
|
|
91
|
+
- lib
|
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ">="
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0'
|
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
|
+
requirements:
|
|
99
|
+
- - ">="
|
|
100
|
+
- !ruby/object:Gem::Version
|
|
101
|
+
version: '0'
|
|
102
|
+
requirements: []
|
|
103
|
+
rubyforge_project:
|
|
104
|
+
rubygems_version: 2.7.7
|
|
105
|
+
signing_key:
|
|
106
|
+
specification_version: 4
|
|
107
|
+
summary: Simple Vending Machine
|
|
108
|
+
test_files: []
|