coinstar 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/coinstar.gemspec +1 -1
- data/lib/coinstar/executable.rb +10 -1
- data/spec/change_machine_spec.rb +8 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ece551c984eda35d63d354c9a06a3e8f5d52bf8d
|
4
|
+
data.tar.gz: 8e46582451aa4e178fb885b3a72d06bcecd4be05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 197af7771053b65e5ffd1a1b66d2686ddce1f60e70a3bf704bda22591449d0ce51b3d97b4b76e8396a228920b767e29a70d23fb6c8cc29ee3b1cb1e1e706cba1
|
7
|
+
data.tar.gz: b2bcb17a1a16bf9631a49c34610ac52448f6daef35b058e669af176fae2ea2d1684644133eedfe6f461404a447829c043760fa79cf1f77913c5601479d131c19
|
data/coinstar.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'coinstar'
|
7
|
-
spec.version = '0.0.
|
7
|
+
spec.version = '0.0.5'
|
8
8
|
spec.authors = ['Brooks Swinnerton']
|
9
9
|
spec.email = ['bswinnerton@gmail.com']
|
10
10
|
spec.description = %q{GA Apprentice Code Challenge}
|
data/lib/coinstar/executable.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Executable
|
2
2
|
def run(args)
|
3
|
-
self.send(args[:argument], args[:params]) if self.respond_to? args[:argument]
|
3
|
+
result = self.send(args[:argument], args[:params]) if self.respond_to? args[:argument]
|
4
|
+
display(result)
|
4
5
|
end
|
5
6
|
|
6
7
|
def clean_input(args)
|
@@ -31,4 +32,12 @@ module Executable
|
|
31
32
|
hash
|
32
33
|
end
|
33
34
|
end
|
35
|
+
|
36
|
+
def display(result)
|
37
|
+
if result.is_a? Hash
|
38
|
+
result.map { |k,v| "#{k}: #{v}" }
|
39
|
+
else
|
40
|
+
result
|
41
|
+
end
|
42
|
+
end
|
34
43
|
end
|
data/spec/change_machine_spec.rb
CHANGED
@@ -62,15 +62,20 @@ describe ChangeMachine do
|
|
62
62
|
|
63
63
|
context 'Takes input from the command line' do
|
64
64
|
it 'makes change' do
|
65
|
-
clean_input = ChangeMachine.clean_input([
|
66
|
-
expect(ChangeMachine.run(clean_input)).to eq(
|
65
|
+
clean_input = ChangeMachine.clean_input(['--make_change', '98'])
|
66
|
+
expect(ChangeMachine.run(clean_input)).to eq( ['quarters: 3', 'dimes: 2', 'pennies: 3'] )
|
67
67
|
end
|
68
68
|
|
69
69
|
it 'makes cents' do
|
70
|
-
clean_input = ChangeMachine.clean_input([
|
70
|
+
clean_input = ChangeMachine.clean_input(['--make_cents', 'quarters=3', 'dimes=2', 'pennies=3'])
|
71
71
|
expect(ChangeMachine.run(clean_input)).to eq( 98 )
|
72
72
|
end
|
73
73
|
|
74
|
+
it 'displays change nicely in the terminal' do
|
75
|
+
clean_input = ChangeMachine.clean_input(['--make_change', '76'])
|
76
|
+
expect(ChangeMachine.run(clean_input)).to eq( ['quarters: 3', 'pennies: 1'] )
|
77
|
+
end
|
78
|
+
|
74
79
|
it 'gracefully fails if an argument isn\'t set' do
|
75
80
|
expect { ChangeMachine.clean_input([]) }.to raise_error 'Please enter either --make_change or --make_cents'
|
76
81
|
end
|