pot_of_coffee 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +37 -14
- data/bin/console +6 -0
- data/bin/pot_of_coffee +11 -11
- data/lib/pot_of_coffee/brewer.rb +26 -0
- data/lib/pot_of_coffee/errors.rb +1 -1
- data/lib/pot_of_coffee/units/imperial.rb +2 -2
- data/lib/pot_of_coffee/units/metric.rb +2 -2
- data/lib/pot_of_coffee/version.rb +1 -1
- data/lib/pot_of_coffee.rb +1 -21
- data/pot_of_coffee.gemspec +1 -0
- data/spec/pot_of_coffee/brewer_spec.rb +6 -7
- data/spec/pot_of_coffee/units_spec.rb +1 -1
- metadata +19 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e503ba1518e82bcf7fd871dde109f4a5f99242e
|
4
|
+
data.tar.gz: 5186eeac0b0ae2b32fde7ce0139094d9250c3510
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6271c15b0634d0939aedcaa3ac5c2e8e07c022fd11723c39f522049ee06aedf2ab5bcc0acf7a515fcab70bee85a74cc108c4c8804e651940b2ee8bff6d62285
|
7
|
+
data.tar.gz: 06317f89de83f904fd91f6dce1c968aa970ee8350b8e4a44b6a2dd032e70e4d6bf15140d05fb8898496610b3eb25c85fa624a3ecf48b106fde352661bc571f4c
|
data/README.md
CHANGED
@@ -24,26 +24,47 @@ Or install it yourself as:
|
|
24
24
|
## Usage
|
25
25
|
|
26
26
|
### CLI
|
27
|
-
```
|
28
|
-
pot_of_coffee
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
```bash
|
28
|
+
$ pot_of_coffee
|
29
|
+
Cups desired: 12
|
30
|
+
Brew strength: medium
|
31
|
+
Grounds needed: 8.1 tbsp
|
32
|
+
|
33
|
+
$ pot_of_coffee --strength=strong
|
34
|
+
Cups desired: 12
|
35
|
+
Brew strength: strong
|
36
|
+
Grounds needed: 10.5 tbsp
|
37
|
+
|
38
|
+
$ pot_of_coffee --strength=blagg
|
39
|
+
Sorry: coffee strength must be strong, medium, or mild
|
40
|
+
|
41
|
+
$ pot_of_coffee --units=metric
|
42
|
+
Cups desired: 12
|
43
|
+
Brew strength: medium
|
44
|
+
Grounds needed: 63.6 g
|
45
|
+
|
32
46
|
```
|
33
47
|
|
34
48
|
### Ruby
|
35
49
|
```ruby
|
36
50
|
require 'pot_of_coffee'
|
37
51
|
|
38
|
-
pot_of_coffee = PotOfCoffee::Brewer.new(quantity: 12, strength: '
|
52
|
+
pot_of_coffee = PotOfCoffee::Brewer.new(quantity: 12, strength: 'mild')
|
39
53
|
pot_of_coffee.amount # 6.0
|
40
|
-
pot_of_coffee.instructions
|
54
|
+
pot_of_coffee.instructions
|
55
|
+
#=> Cups desired: 12
|
56
|
+
#=> Brew strength: mild
|
57
|
+
#=> Grounds needed: 6.0 tbsp
|
58
|
+
|
41
59
|
|
42
60
|
# Metric units
|
43
61
|
|
44
|
-
pot_of_coffee = PotOfCoffee::Brewer.new(units: PotOfCoffee::
|
62
|
+
pot_of_coffee = PotOfCoffee::Brewer.new(units: PotOfCoffee::Units::Metric.new)
|
45
63
|
pot_of_coffee.amount # 63.6
|
46
|
-
pot_of_coffee.instructions
|
64
|
+
pot_of_coffee.instructions
|
65
|
+
#=> Cups desired: 12
|
66
|
+
#=> Brew strength: medium
|
67
|
+
#=> Grounds needed: 63.6 g
|
47
68
|
```
|
48
69
|
|
49
70
|
## Using your own units
|
@@ -52,7 +73,7 @@ Just supply an object that responds to `name`, `abbreviation`, and `table`.
|
|
52
73
|
`name` and `abbreviation` must be strings.
|
53
74
|
`name` is not used at the moment, but it may be in the future.
|
54
75
|
`table` must be a hash.
|
55
|
-
I chose to provide three keys: `:strong`, `:
|
76
|
+
I chose to provide three keys: `:strong`, `:medium`, and `:mild`, but you can use whatever you'd like.
|
56
77
|
|
57
78
|
### Example
|
58
79
|
```ruby
|
@@ -70,19 +91,21 @@ class CorgeUnit
|
|
70
91
|
def table
|
71
92
|
{
|
72
93
|
strong: 3900,
|
73
|
-
|
74
|
-
|
94
|
+
medium: 200,
|
95
|
+
mild: 100
|
75
96
|
}
|
76
97
|
end
|
77
98
|
end
|
78
99
|
|
79
|
-
pot_of_coffee = PotOfCoffee::Brewer.new(quantity: 3, strength: :
|
100
|
+
pot_of_coffee = PotOfCoffee::Brewer.new(quantity: 3, strength: :mild, units: CorgeUnit.new)
|
80
101
|
pot_of_coffee.amount # 300
|
81
102
|
```
|
82
103
|
|
83
104
|
## Tests
|
84
105
|
|
85
|
-
|
106
|
+
* Fork/clone the repo
|
107
|
+
* `bundle install`
|
108
|
+
* `bundle exec rspec`
|
86
109
|
|
87
110
|
## Contributing
|
88
111
|
|
data/bin/console
ADDED
data/bin/pot_of_coffee
CHANGED
@@ -5,7 +5,7 @@ require 'pot_of_coffee'
|
|
5
5
|
|
6
6
|
options = {
|
7
7
|
quantity: 12,
|
8
|
-
strength: :
|
8
|
+
strength: :medium,
|
9
9
|
units: PotOfCoffee::Units::Imperial.new
|
10
10
|
}
|
11
11
|
|
@@ -16,27 +16,27 @@ OptionParser.new do |opts|
|
|
16
16
|
options[:quantity] = v
|
17
17
|
end
|
18
18
|
|
19
|
-
opts.on('-s', '--strength [STRENGTH]', String, 'Strength of your coffee (
|
19
|
+
opts.on('-s', '--strength [STRENGTH]', String, 'Strength of your coffee (medium, strong, mild)') do |v|
|
20
20
|
options[:strength] = v.to_sym
|
21
21
|
end
|
22
22
|
|
23
23
|
opts.on('-u', '--units [UNITS]', 'Units for your coffee brew (imperial, metric)') do |v|
|
24
24
|
options[:units] = case v
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
when 'metric'
|
26
|
+
PotOfCoffee::Units::Metric.new
|
27
|
+
when 'imperial'
|
28
|
+
PotOfCoffee::Units::Imperial.new
|
29
|
+
else
|
30
|
+
puts "#{v} is not 'imperial' or 'metric'"
|
31
|
+
exit
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
opts.on('-h', '--help', 'Display this screen'
|
35
|
+
opts.on('-h', '--help', 'Display this screen') do
|
36
36
|
puts opts
|
37
37
|
exit
|
38
38
|
end
|
39
39
|
end.parse!
|
40
40
|
|
41
41
|
pot_of_coffee = PotOfCoffee::Brewer.new(**options)
|
42
|
-
puts pot_of_coffee.instructions
|
42
|
+
puts pot_of_coffee.instructions
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module PotOfCoffee
|
2
|
+
class Brewer
|
3
|
+
attr_reader :units, :quantity, :strength
|
4
|
+
|
5
|
+
def initialize(quantity: 12, strength: :medium, units: Units::Imperial.new)
|
6
|
+
fail NegativeNumberError unless quantity > 0
|
7
|
+
fail WrongStrengthError unless units.table.keys.include?(strength)
|
8
|
+
|
9
|
+
@quantity = quantity
|
10
|
+
@strength = strength
|
11
|
+
@units = units
|
12
|
+
end
|
13
|
+
|
14
|
+
def grounds
|
15
|
+
(quantity * units.table.fetch(strength)).round(2)
|
16
|
+
end
|
17
|
+
|
18
|
+
def instructions
|
19
|
+
<<~INSTRUCTIONS
|
20
|
+
Cups desired: #{quantity}
|
21
|
+
Brew strength: #{strength}
|
22
|
+
Grounds needed: #{grounds} #{units.abbreviation}
|
23
|
+
INSTRUCTIONS
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/pot_of_coffee/errors.rb
CHANGED
data/lib/pot_of_coffee.rb
CHANGED
@@ -1,28 +1,8 @@
|
|
1
|
+
require 'pot_of_coffee/brewer'
|
1
2
|
require 'pot_of_coffee/version'
|
2
3
|
require 'pot_of_coffee/units'
|
3
4
|
require 'pot_of_coffee/errors'
|
4
5
|
|
5
6
|
module PotOfCoffee
|
6
|
-
class Brewer
|
7
|
-
attr_reader :units, :quantity, :strength
|
8
7
|
|
9
|
-
def initialize(quantity: 12, strength: :normal, units: Units::Imperial.new)
|
10
|
-
fail NegativeNumberError unless quantity > 0
|
11
|
-
fail WrongStrengthError unless units.table.keys.include?(strength)
|
12
|
-
|
13
|
-
@quantity = quantity
|
14
|
-
@strength = strength
|
15
|
-
@units = units
|
16
|
-
# rescue NegativeNumberError, WrongStrengthError => e
|
17
|
-
# print e.message
|
18
|
-
end
|
19
|
-
|
20
|
-
def amount
|
21
|
-
(quantity * units.table.fetch(strength)).round(2)
|
22
|
-
end
|
23
|
-
|
24
|
-
def instructions
|
25
|
-
"To make #{quantity} cups of of #{strength} coffee, use #{amount} #{units.abbreviation} of grounds."
|
26
|
-
end
|
27
|
-
end
|
28
8
|
end
|
data/pot_of_coffee.gemspec
CHANGED
@@ -3,9 +3,9 @@ RSpec.describe PotOfCoffee::Brewer do
|
|
3
3
|
let(:pot_of_coffee) { PotOfCoffee::Brewer.new }
|
4
4
|
|
5
5
|
it 'has correct properties and gives instructions' do
|
6
|
-
expect(pot_of_coffee.instructions).to eq(
|
6
|
+
expect(pot_of_coffee.instructions).to eq("Cups desired: 12\nBrew strength: medium\nGrounds needed: 8.1 tbsp\n")
|
7
7
|
expect(pot_of_coffee.quantity).to eq(12)
|
8
|
-
expect(pot_of_coffee.strength).to eq(:
|
8
|
+
expect(pot_of_coffee.strength).to eq(:medium)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
@@ -35,17 +35,16 @@ RSpec.describe PotOfCoffee::Brewer do
|
|
35
35
|
def table
|
36
36
|
{
|
37
37
|
strong: 109109,
|
38
|
-
|
39
|
-
|
38
|
+
medium: 279.10,
|
39
|
+
mild: 100
|
40
40
|
}
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
let(:
|
45
|
-
let(:pot_of_coffee) { PotOfCoffee::Brewer.new(units: units) }
|
44
|
+
let(:pot_of_coffee) { PotOfCoffee::Brewer.new(units: WhateverUnit.new) }
|
46
45
|
|
47
46
|
it 'can provide your own units' do
|
48
|
-
expect(pot_of_coffee.instructions).to eq(
|
47
|
+
expect(pot_of_coffee.instructions).to eq("Cups desired: 12\nBrew strength: medium\nGrounds needed: 3349.2 gb\n")
|
49
48
|
end
|
50
49
|
end
|
51
50
|
end
|
@@ -11,7 +11,7 @@ RSpec.shared_examples 'a correct unit' do
|
|
11
11
|
|
12
12
|
describe '#table' do
|
13
13
|
subject { units.table }
|
14
|
-
it { is_expected.to satisfy { |t| [:weak, :
|
14
|
+
it { is_expected.to satisfy { |t| [:weak, :medium, :strong].each { |key| t.keys.include?(key) } } }
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pot_of_coffee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dave Shaffer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 3.6.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.11'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.11'
|
55
69
|
description: This is a small CLI app for calculating the brew strength for an automatic
|
56
70
|
drip coffee maker. It can help keep coffee brews consistent.
|
57
71
|
email:
|
@@ -67,8 +81,10 @@ files:
|
|
67
81
|
- LICENSE.txt
|
68
82
|
- README.md
|
69
83
|
- Rakefile
|
84
|
+
- bin/console
|
70
85
|
- bin/pot_of_coffee
|
71
86
|
- lib/pot_of_coffee.rb
|
87
|
+
- lib/pot_of_coffee/brewer.rb
|
72
88
|
- lib/pot_of_coffee/errors.rb
|
73
89
|
- lib/pot_of_coffee/units.rb
|
74
90
|
- lib/pot_of_coffee/units/imperial.rb
|
@@ -98,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
114
|
version: '0'
|
99
115
|
requirements: []
|
100
116
|
rubyforge_project:
|
101
|
-
rubygems_version: 2.
|
117
|
+
rubygems_version: 2.6.8
|
102
118
|
signing_key:
|
103
119
|
specification_version: 4
|
104
120
|
summary: Coffee brew strength calculator
|