pot_of_coffee 0.1.4 → 0.2.0
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 +4 -4
- data/.gitignore +2 -1
- data/.rspec +1 -0
- data/README.md +6 -4
- data/bin/pot_of_coffee +6 -6
- data/lib/pot_of_coffee/units/imperial.rb +21 -0
- data/lib/pot_of_coffee/units/metric.rb +21 -0
- data/lib/pot_of_coffee/units.rb +4 -40
- data/lib/pot_of_coffee/version.rb +1 -1
- data/lib/pot_of_coffee.rb +10 -27
- data/pot_of_coffee.gemspec +12 -12
- data/spec/pot_of_coffee/brewer_spec.rb +51 -0
- data/spec/pot_of_coffee/units_spec.rb +30 -0
- data/spec/spec_helper.rb +23 -0
- metadata +17 -16
- data/test/helper.rb +0 -3
- data/test/test_brewer.rb +0 -28
- data/test/test_units.rb +0 -21
- data/test/whatever_unit.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05089f2f5028931efeef8f99a977f53aa21944cf
|
4
|
+
data.tar.gz: 4013f9a0776ec654aefb93b4a1db160b1788d3da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c1adc9f7a15d11e5865281e60ae48c987ab227a514ea549aacbc5496a3a8024d54bc771009bb1570f527aadafe1d4182e36a46dd4022e0c378de581ec2de392
|
7
|
+
data.tar.gz: bf637452cd89bbd69779c27b8ba4a6bc0b3d1a62d88c38d48f827f3841d0e3e42131b60b4322fa215dd1a2b6aee0cd4047b88e2fee5c531bca18196dfb5b9bf4
|
data/.gitignore
CHANGED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/README.md
CHANGED
@@ -25,8 +25,10 @@ Or install it yourself as:
|
|
25
25
|
|
26
26
|
### CLI
|
27
27
|
```ruby
|
28
|
-
pot_of_coffee
|
29
|
-
pot_of_coffee
|
28
|
+
pot_of_coffee # "To make 12 cups of normal coffee, use 8.1 tbsp of grounds."
|
29
|
+
pot_of_coffee --strength strong # "To make 12 cups of strong coffee, use 10.5 tbsp of grounds."
|
30
|
+
pot_of_coffee --quantity 11 --strength blagg # "Sorry: coffee strength must be strong, normal, or weak"
|
31
|
+
pot_of_coffee --units metric #To make 12 cups of coffee, use 63.6 g of grounds."
|
30
32
|
```
|
31
33
|
|
32
34
|
### Ruby
|
@@ -35,13 +37,13 @@ require 'pot_of_coffee'
|
|
35
37
|
|
36
38
|
pot_of_coffee = PotOfCoffee::Brewer.new(quantity: 12, strength: 'weak')
|
37
39
|
pot_of_coffee.amount # 6.0
|
38
|
-
pot_of_coffee.instructions # 'To make 12 cups of normal
|
40
|
+
pot_of_coffee.instructions # 'To make 12 cups of normal coffee, use 6.0 tbsp of grounds.'
|
39
41
|
|
40
42
|
# Metric units
|
41
43
|
|
42
44
|
pot_of_coffee = PotOfCoffee::Brewer.new(units: PotOfCoffee::MetricUnit.new)
|
43
45
|
pot_of_coffee.amount # 63.6
|
44
|
-
pot_of_coffee.instructions # 'To make 12 cups of normal
|
46
|
+
pot_of_coffee.instructions # 'To make 12 cups of normal coffee, use 63.6 g of grounds.'
|
45
47
|
```
|
46
48
|
|
47
49
|
## Using your own units
|
data/bin/pot_of_coffee
CHANGED
@@ -6,7 +6,7 @@ require 'pot_of_coffee'
|
|
6
6
|
options = {
|
7
7
|
quantity: 12,
|
8
8
|
strength: :normal,
|
9
|
-
units: PotOfCoffee::
|
9
|
+
units: PotOfCoffee::Units::Imperial.new
|
10
10
|
}
|
11
11
|
|
12
12
|
OptionParser.new do |opts|
|
@@ -20,23 +20,23 @@ OptionParser.new do |opts|
|
|
20
20
|
options[:strength] = v.to_sym
|
21
21
|
end
|
22
22
|
|
23
|
-
opts.on('-u', '--units [UNITS]', 'Units for your coffee brew (imperial, metric)')
|
23
|
+
opts.on('-u', '--units [UNITS]', 'Units for your coffee brew (imperial, metric)') do |v|
|
24
24
|
options[:units] = case v
|
25
25
|
when 'metric'
|
26
|
-
PotOfCoffee::
|
26
|
+
PotOfCoffee::Units::Metric.new
|
27
27
|
when 'imperial'
|
28
|
-
PotOfCoffee::
|
28
|
+
PotOfCoffee::Units::Imperial.new
|
29
29
|
else
|
30
30
|
puts "#{v} is not 'imperial' or 'metric'"
|
31
31
|
exit
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
opts.on(
|
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
|
-
pot_of_coffee = PotOfCoffee::Brewer.new(options)
|
41
|
+
pot_of_coffee = PotOfCoffee::Brewer.new(**options)
|
42
42
|
puts pot_of_coffee.instructions
|
data/lib/pot_of_coffee/units.rb
CHANGED
@@ -1,43 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
def name; raise NotImplementedError; end
|
4
|
-
def abbreviation; raise NotImplementedError; end
|
5
|
-
def table; raise NotImplementedError; end
|
6
|
-
end
|
7
|
-
|
8
|
-
class ImperialUnit < Unit
|
9
|
-
def name
|
10
|
-
'tablespoon'
|
11
|
-
end
|
1
|
+
require 'pot_of_coffee/units/imperial'
|
2
|
+
require 'pot_of_coffee/units/metric'
|
12
3
|
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
def table
|
18
|
-
{
|
19
|
-
weak: 0.5,
|
20
|
-
normal: 0.675,
|
21
|
-
strong: 0.875,
|
22
|
-
}
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
class MetricUnit < Unit
|
27
|
-
def name
|
28
|
-
'gram'
|
29
|
-
end
|
30
|
-
|
31
|
-
def abbreviation
|
32
|
-
'g'
|
33
|
-
end
|
34
|
-
|
35
|
-
def table
|
36
|
-
{
|
37
|
-
weak: 3,
|
38
|
-
normal: 5.3,
|
39
|
-
strong: 10.6
|
40
|
-
}
|
41
|
-
end
|
4
|
+
module PotOfCoffee
|
5
|
+
module Units
|
42
6
|
end
|
43
7
|
end
|
data/lib/pot_of_coffee.rb
CHANGED
@@ -1,45 +1,28 @@
|
|
1
1
|
require 'pot_of_coffee/version'
|
2
2
|
require 'pot_of_coffee/units'
|
3
3
|
require 'pot_of_coffee/errors'
|
4
|
-
require 'forwardable'
|
5
4
|
|
6
5
|
module PotOfCoffee
|
7
6
|
class Brewer
|
8
|
-
|
9
|
-
attr_reader :units
|
7
|
+
attr_reader :units, :quantity, :strength
|
10
8
|
|
11
|
-
|
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
12
|
|
13
|
-
|
14
|
-
@
|
15
|
-
@
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
def quantity
|
20
|
-
if @quantity > 0
|
21
|
-
@quantity
|
22
|
-
else
|
23
|
-
raise NegativeNumberError
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def strength
|
28
|
-
if ratios.include?(@strength.to_sym)
|
29
|
-
@strength
|
30
|
-
else
|
31
|
-
raise WrongStrengthError
|
32
|
-
end
|
13
|
+
@quantity = quantity
|
14
|
+
@strength = strength
|
15
|
+
@units = units
|
16
|
+
# rescue NegativeNumberError, WrongStrengthError => e
|
17
|
+
# print e.message
|
33
18
|
end
|
34
19
|
|
35
20
|
def amount
|
36
|
-
(quantity *
|
21
|
+
(quantity * units.table.fetch(strength)).round(2)
|
37
22
|
end
|
38
23
|
|
39
24
|
def instructions
|
40
25
|
"To make #{quantity} cups of of #{strength} coffee, use #{amount} #{units.abbreviation} of grounds."
|
41
|
-
rescue NegativeNumberError, WrongStrengthError => e
|
42
|
-
print e.message
|
43
26
|
end
|
44
27
|
end
|
45
28
|
end
|
data/pot_of_coffee.gemspec
CHANGED
@@ -4,21 +4,21 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'pot_of_coffee/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'pot_of_coffee'
|
8
8
|
spec.version = PotOfCoffee::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
9
|
+
spec.authors = ['Dave Shaffer']
|
10
|
+
spec.email = ['dave.shaffer@gmail.com']
|
11
|
+
spec.summary = 'Coffee brew strength calculator'
|
12
|
+
spec.description = 'This is a small CLI app for calculating the brew strength for an automatic drip coffee maker. It can help keep coffee brews consistent.'
|
13
|
+
spec.homepage = 'http://daveshaffer.co/coffee'
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
17
|
-
spec.executables = [
|
17
|
+
spec.executables = ['pot_of_coffee']
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_development_dependency
|
22
|
-
spec.add_development_dependency
|
23
|
-
spec.add_development_dependency
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'rspec', '~> 3.6.0'
|
24
24
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
RSpec.describe PotOfCoffee::Brewer do
|
2
|
+
context 'with no arguments' do
|
3
|
+
let(:pot_of_coffee) { PotOfCoffee::Brewer.new }
|
4
|
+
|
5
|
+
it 'has correct properties and gives instructions' do
|
6
|
+
expect(pot_of_coffee.instructions).to eq('To make 12 cups of of normal coffee, use 8.1 tbsp of grounds.')
|
7
|
+
expect(pot_of_coffee.quantity).to eq(12)
|
8
|
+
expect(pot_of_coffee.strength).to eq(:normal)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'with invalid quantity' do
|
13
|
+
it 'raises PotOfCoffee::NegativeNumberError' do
|
14
|
+
expect { PotOfCoffee::Brewer.new(quantity: -1) }.to raise_error(PotOfCoffee::NegativeNumberError)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'with invalid strength' do
|
19
|
+
it 'raises PotOfCoffee::WrongStrengthError' do
|
20
|
+
expect { PotOfCoffee::Brewer.new(strength: :ultra) }.to raise_error(PotOfCoffee::WrongStrengthError)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
context 'with own units' do
|
26
|
+
class WhateverUnit
|
27
|
+
def name
|
28
|
+
'grably'
|
29
|
+
end
|
30
|
+
|
31
|
+
def abbreviation
|
32
|
+
'gb'
|
33
|
+
end
|
34
|
+
|
35
|
+
def table
|
36
|
+
{
|
37
|
+
strong: 109109,
|
38
|
+
normal: 279.10,
|
39
|
+
weak: 100
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
let(:units) { WhateverUnit.new }
|
45
|
+
let(:pot_of_coffee) { PotOfCoffee::Brewer.new(units: units) }
|
46
|
+
|
47
|
+
it 'can provide your own units' do
|
48
|
+
expect(pot_of_coffee.instructions).to eq('To make 12 cups of of normal coffee, use 3349.2 gb of grounds.')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
RSpec.shared_examples 'a correct unit' do
|
2
|
+
describe '#name' do
|
3
|
+
subject { units.name }
|
4
|
+
it { is_expected.to be_a(String) }
|
5
|
+
end
|
6
|
+
|
7
|
+
describe '#abbreviation' do
|
8
|
+
subject { units.abbreviation }
|
9
|
+
it { is_expected.to be_a(String) }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#table' do
|
13
|
+
subject { units.table }
|
14
|
+
it { is_expected.to satisfy { |t| [:weak, :normal, :strong].each { |key| t.keys.include?(key) } } }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
RSpec.describe PotOfCoffee::Units do
|
19
|
+
describe 'imperial units' do
|
20
|
+
let(:units) { PotOfCoffee::Units::Imperial.new }
|
21
|
+
|
22
|
+
it_behaves_like 'a correct unit'
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'metric units' do
|
26
|
+
let(:units) { PotOfCoffee::Units::Metric.new }
|
27
|
+
|
28
|
+
it_behaves_like 'a correct unit'
|
29
|
+
end
|
30
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'pot_of_coffee'
|
2
|
+
|
3
|
+
RSpec.configure do |config|
|
4
|
+
config.expect_with :rspec do |expectations|
|
5
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
6
|
+
end
|
7
|
+
|
8
|
+
config.mock_with :rspec do |mocks|
|
9
|
+
mocks.verify_partial_doubles = true
|
10
|
+
end
|
11
|
+
|
12
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
13
|
+
config.filter_run_when_matching :focus
|
14
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
15
|
+
config.disable_monkey_patching!
|
16
|
+
config.warnings = true
|
17
|
+
if config.files_to_run.one?
|
18
|
+
config.default_formatter = "doc"
|
19
|
+
end
|
20
|
+
|
21
|
+
config.order = :random
|
22
|
+
Kernel.srand config.seed
|
23
|
+
end
|
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.2.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:
|
11
|
+
date: 2017-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -39,19 +39,19 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 3.6.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 3.6.0
|
55
55
|
description: This is a small CLI app for calculating the brew strength for an automatic
|
56
56
|
drip coffee maker. It can help keep coffee brews consistent.
|
57
57
|
email:
|
@@ -62,6 +62,7 @@ extensions: []
|
|
62
62
|
extra_rdoc_files: []
|
63
63
|
files:
|
64
64
|
- ".gitignore"
|
65
|
+
- ".rspec"
|
65
66
|
- Gemfile
|
66
67
|
- LICENSE.txt
|
67
68
|
- README.md
|
@@ -70,12 +71,13 @@ files:
|
|
70
71
|
- lib/pot_of_coffee.rb
|
71
72
|
- lib/pot_of_coffee/errors.rb
|
72
73
|
- lib/pot_of_coffee/units.rb
|
74
|
+
- lib/pot_of_coffee/units/imperial.rb
|
75
|
+
- lib/pot_of_coffee/units/metric.rb
|
73
76
|
- lib/pot_of_coffee/version.rb
|
74
77
|
- pot_of_coffee.gemspec
|
75
|
-
-
|
76
|
-
-
|
77
|
-
-
|
78
|
-
- test/whatever_unit.rb
|
78
|
+
- spec/pot_of_coffee/brewer_spec.rb
|
79
|
+
- spec/pot_of_coffee/units_spec.rb
|
80
|
+
- spec/spec_helper.rb
|
79
81
|
homepage: http://daveshaffer.co/coffee
|
80
82
|
licenses:
|
81
83
|
- MIT
|
@@ -96,12 +98,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
98
|
version: '0'
|
97
99
|
requirements: []
|
98
100
|
rubyforge_project:
|
99
|
-
rubygems_version: 2.
|
101
|
+
rubygems_version: 2.5.1
|
100
102
|
signing_key:
|
101
103
|
specification_version: 4
|
102
104
|
summary: Coffee brew strength calculator
|
103
105
|
test_files:
|
104
|
-
-
|
105
|
-
-
|
106
|
-
-
|
107
|
-
- test/whatever_unit.rb
|
106
|
+
- spec/pot_of_coffee/brewer_spec.rb
|
107
|
+
- spec/pot_of_coffee/units_spec.rb
|
108
|
+
- spec/spec_helper.rb
|
data/test/helper.rb
DELETED
data/test/test_brewer.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestBrewer < Minitest::Test
|
4
|
-
def test_gives_instructions_with_no_arguments
|
5
|
-
@pot_of_coffee = PotOfCoffee::Brewer.new
|
6
|
-
assert_equal @pot_of_coffee.instructions, "To make 12 cups of of normal coffee, use 8.1 tbsp of grounds."
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_has_correct_properties_when_created_with_no_arguments
|
10
|
-
@pot_of_coffee = PotOfCoffee::Brewer.new
|
11
|
-
assert_equal @pot_of_coffee.quantity, 12
|
12
|
-
assert_equal @pot_of_coffee.strength, :normal
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_quantity_must_be_positive
|
16
|
-
@pot_of_coffee = PotOfCoffee::Brewer.new(quantity: -1)
|
17
|
-
assert_raises PotOfCoffee::NegativeNumberError do
|
18
|
-
@pot_of_coffee.quantity
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_strength_must_be_strong_normal_or_weak
|
23
|
-
@pot_of_coffee = PotOfCoffee::Brewer.new(quantity: rand(24), strength: :ultra)
|
24
|
-
assert_raises PotOfCoffee::WrongStrengthError do
|
25
|
-
@pot_of_coffee.strength
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
data/test/test_units.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
require 'whatever_unit'
|
3
|
-
|
4
|
-
class TestUnits < Minitest::Test
|
5
|
-
def test_can_use_metric_units
|
6
|
-
@pot_of_coffee = PotOfCoffee::Brewer.new(units: PotOfCoffee::MetricUnit.new)
|
7
|
-
assert_equal @pot_of_coffee.instructions, 'To make 12 cups of of normal coffee, use 63.6 g of grounds.'
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_can_provide_your_own_units
|
11
|
-
@pot_of_coffee = PotOfCoffee::Brewer.new(units: WhateverUnit.new)
|
12
|
-
assert_equal @pot_of_coffee.instructions, 'To make 12 cups of of normal coffee, use 3349.2 gb of grounds.'
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_units_must_respond_to_correct_things
|
16
|
-
@whatever_unit = WhateverUnit.new
|
17
|
-
assert_respond_to @whatever_unit, :name
|
18
|
-
assert_respond_to @whatever_unit, :abbreviation
|
19
|
-
assert_respond_to @whatever_unit, :table
|
20
|
-
end
|
21
|
-
end
|