coinstar 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +35 -32
- data/coinstar.gemspec +2 -1
- data/lib/coinstar/change_machine.rb +2 -15
- data/lib/coinstar/executable.rb +3 -3
- data/spec/change_machine_spec.rb +10 -7
- data/spec/spec_helper.rb +4 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a2960ea4b6ebd5418cdd74ff2798a1ce619f502
|
4
|
+
data.tar.gz: 1940c666e1f7b8fc1db9a142749d871eca6e457c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df32bb6cc0d6bc85375339fc31659f24f68e802639f9e3416cb4c3485994e2b8d352372cb0cb14b952ea18a811f858ab52f453605518edd5dd1975b2d748aa2e
|
7
|
+
data.tar.gz: 3c6b729d1b6cff6ef7062ca6bcb5de5fbefc7cb00dbfe515c39cb07860ed116a0c8991c6acfe1c3c455012af349fd3540db58e066d33a9c52275e7adf578eac0
|
data/README.md
CHANGED
@@ -1,3 +1,38 @@
|
|
1
|
+
# Coinstar
|
2
|
+
[![Build Status](https://travis-ci.org/bswinnerton/coinstar.png)](https://travis-ci.org/bswinnerton/coinstar)
|
3
|
+
[![Code Climate](https://codeclimate.com/github/bswinnerton/coinstar.png)](https://codeclimate.com/github/bswinnerton/coinstar)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/bswinnerton/coinstar/badge.png?branch=master)](https://coveralls.io/r/bswinnerton/coinstar?branch=master)
|
5
|
+
|
6
|
+
##### Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'coinstar'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install coinstar
|
19
|
+
|
20
|
+
##### Usage
|
21
|
+
|
22
|
+
Simply call `coinstar` as so:
|
23
|
+
|
24
|
+
```
|
25
|
+
$ coinstar --make_change 98
|
26
|
+
```
|
27
|
+
|
28
|
+
or
|
29
|
+
|
30
|
+
```
|
31
|
+
$ coinstar --make_cents quarters=1 dimes=2 nickels=3 pennies=4
|
32
|
+
```
|
33
|
+
|
34
|
+
#####Requirements
|
35
|
+
|
1
36
|
![GA_Logo](https://raw.github.com/generalassembly/ga-ruby-on-rails-for-devs/master/images/ga.png)
|
2
37
|
|
3
38
|
|
@@ -53,35 +88,3 @@ Your program should provide for the following functionality:
|
|
53
88
|
- Simplicity/elegance of design (be prepared to discuss)
|
54
89
|
- Maintainability (clean, code that is easy to understand and change)
|
55
90
|
- Testing (We encourage RSpec)
|
56
|
-
|
57
|
-
|
58
|
-
### Gem Documentation
|
59
|
-
[![Build Status](https://travis-ci.org/bswinnerton/coinstar.png)](https://travis-ci.org/bswinnerton/coinstar)
|
60
|
-
|
61
|
-
##### Installation
|
62
|
-
|
63
|
-
Add this line to your application's Gemfile:
|
64
|
-
|
65
|
-
gem 'coinstar'
|
66
|
-
|
67
|
-
And then execute:
|
68
|
-
|
69
|
-
$ bundle
|
70
|
-
|
71
|
-
Or install it yourself as:
|
72
|
-
|
73
|
-
$ gem install coinstar
|
74
|
-
|
75
|
-
##### Usage
|
76
|
-
|
77
|
-
Simply call `coinstar` as so:
|
78
|
-
|
79
|
-
```
|
80
|
-
coinstar --make_change 98
|
81
|
-
```
|
82
|
-
|
83
|
-
or
|
84
|
-
|
85
|
-
```
|
86
|
-
coinstar --make_cents quarters=1 dimes=2 nickels=3 pennies=4
|
87
|
-
```
|
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.4'
|
8
8
|
spec.authors = ['Brooks Swinnerton']
|
9
9
|
spec.email = ['bswinnerton@gmail.com']
|
10
10
|
spec.description = %q{GA Apprentice Code Challenge}
|
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_development_dependency 'rake'
|
22
22
|
spec.add_development_dependency 'pry'
|
23
23
|
spec.add_development_dependency 'rspec'
|
24
|
+
spec.add_development_dependency 'coveralls'
|
24
25
|
|
25
26
|
spec.add_runtime_dependency 'activesupport'
|
26
27
|
end
|
@@ -11,18 +11,17 @@ class ChangeMachine
|
|
11
11
|
calculated_change = sorted_currency.inject({}) do |change, (k,v)|
|
12
12
|
unless cents < v
|
13
13
|
divisible = cents / v
|
14
|
-
change[k] = divisible
|
14
|
+
change[k.to_s.pluralize.to_sym] = divisible
|
15
15
|
cents -= (CURRENCY[k] * divisible)
|
16
16
|
end
|
17
17
|
change
|
18
18
|
end
|
19
|
-
pluralize(calculated_change)
|
20
19
|
end
|
21
20
|
|
22
21
|
def self.make_cents(currency)
|
23
22
|
begin
|
24
23
|
currency.inject(0) do |cents, (k,v)|
|
25
|
-
cents += (CURRENCY[singularize
|
24
|
+
cents += (CURRENCY[k.to_s.singularize.to_sym] * v)
|
26
25
|
cents
|
27
26
|
end
|
28
27
|
rescue NoMethodError
|
@@ -35,16 +34,4 @@ class ChangeMachine
|
|
35
34
|
def self.sorted_currency
|
36
35
|
Hash[CURRENCY.sort_by{|k, v| v}.reverse]
|
37
36
|
end
|
38
|
-
|
39
|
-
def self.pluralize(hash)
|
40
|
-
hash.inject({}) do |plural_hash, (k,v)|
|
41
|
-
plural_key = k.to_s.pluralize
|
42
|
-
plural_hash[plural_key.to_sym] = v
|
43
|
-
plural_hash
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def self.singularize(symbol)
|
48
|
-
symbol.to_s.singularize.to_sym
|
49
|
-
end
|
50
37
|
end
|
data/lib/coinstar/executable.rb
CHANGED
@@ -11,7 +11,6 @@ module Executable
|
|
11
11
|
rescue NoMethodError
|
12
12
|
raise 'Please enter either --make_change or --make_cents'
|
13
13
|
end
|
14
|
-
|
15
14
|
begin
|
16
15
|
params = params.first.to_i if arg == :make_change
|
17
16
|
params = params_to_hash(params) if arg == :make_cents
|
@@ -19,6 +18,7 @@ module Executable
|
|
19
18
|
raise 'Please enter the change amount' if arg == :make_change
|
20
19
|
raise 'Please enter the cents as quarters=25 format' if arg == :make_cents
|
21
20
|
end
|
21
|
+
|
22
22
|
{argument: arg, params: params}
|
23
23
|
end
|
24
24
|
|
@@ -26,8 +26,8 @@ module Executable
|
|
26
26
|
|
27
27
|
def params_to_hash(params)
|
28
28
|
params.inject({}) do |hash, param|
|
29
|
-
|
30
|
-
hash[
|
29
|
+
array = param.split('=')
|
30
|
+
hash[array.first.to_sym] = array.last.to_i
|
31
31
|
hash
|
32
32
|
end
|
33
33
|
end
|
data/spec/change_machine_spec.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'pry'
|
3
2
|
|
4
3
|
describe ChangeMachine do
|
5
4
|
context 'Makes change from a given amount of cents and returns a currency set' do
|
@@ -26,7 +25,7 @@ describe ChangeMachine do
|
|
26
25
|
|
27
26
|
context 'Makes change for quantities up to 100 cents' do
|
28
27
|
it 'gracefully handles quanities larger than 100' do
|
29
|
-
expect { ChangeMachine.make_change(102) }.to raise_error
|
28
|
+
expect { ChangeMachine.make_change(102) }.to raise_error 'You\'re going to need a bigger change machine'
|
30
29
|
end
|
31
30
|
end
|
32
31
|
|
@@ -64,20 +63,24 @@ describe ChangeMachine do
|
|
64
63
|
context 'Takes input from the command line' do
|
65
64
|
it 'makes change' do
|
66
65
|
clean_input = ChangeMachine.clean_input(["--make_change", "98"])
|
67
|
-
expect(ChangeMachine.run(clean_input)).to eq({:
|
66
|
+
expect(ChangeMachine.run(clean_input)).to eq( {quarters: 3, dimes: 2, pennies: 3} )
|
68
67
|
end
|
69
68
|
|
70
69
|
it 'makes cents' do
|
71
70
|
clean_input = ChangeMachine.clean_input(["--make_cents", "quarters=3", "dimes=2", "pennies=3"])
|
72
|
-
expect(ChangeMachine.run(clean_input)).to eq 98
|
71
|
+
expect(ChangeMachine.run(clean_input)).to eq( 98 )
|
73
72
|
end
|
74
73
|
|
75
74
|
it 'gracefully fails if an argument isn\'t set' do
|
76
|
-
expect { ChangeMachine.clean_input([]) }.to raise_error
|
75
|
+
expect { ChangeMachine.clean_input([]) }.to raise_error 'Please enter either --make_change or --make_cents'
|
77
76
|
end
|
78
77
|
|
79
|
-
it 'gracefully fails if parameters aren\'t set' do
|
80
|
-
expect { ChangeMachine.clean_input(["--make_change"]) }.to raise_error
|
78
|
+
it 'gracefully fails if parameters aren\'t set with make_change' do
|
79
|
+
expect { ChangeMachine.clean_input(["--make_change"]) }.to raise_error 'Please enter the change amount'
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'gracefully fails if parameters aren\'t set with make_cents' do
|
83
|
+
expect { ChangeMachine.clean_input(["--make_cents"]) }.to raise_error 'Please enter the cents as quarters=25 format'
|
81
84
|
end
|
82
85
|
end
|
83
86
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coinstar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brooks Swinnerton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: coveralls
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: activesupport
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|