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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 05089f2f5028931efeef8f99a977f53aa21944cf
4
- data.tar.gz: 4013f9a0776ec654aefb93b4a1db160b1788d3da
3
+ metadata.gz: 1e503ba1518e82bcf7fd871dde109f4a5f99242e
4
+ data.tar.gz: 5186eeac0b0ae2b32fde7ce0139094d9250c3510
5
5
  SHA512:
6
- metadata.gz: 2c1adc9f7a15d11e5865281e60ae48c987ab227a514ea549aacbc5496a3a8024d54bc771009bb1570f527aadafe1d4182e36a46dd4022e0c378de581ec2de392
7
- data.tar.gz: bf637452cd89bbd69779c27b8ba4a6bc0b3d1a62d88c38d48f827f3841d0e3e42131b60b4322fa215dd1a2b6aee0cd4047b88e2fee5c531bca18196dfb5b9bf4
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
- ```ruby
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."
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: 'weak')
52
+ pot_of_coffee = PotOfCoffee::Brewer.new(quantity: 12, strength: 'mild')
39
53
  pot_of_coffee.amount # 6.0
40
- pot_of_coffee.instructions # 'To make 12 cups of normal coffee, use 6.0 tbsp of grounds.'
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::MetricUnit.new)
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 # 'To make 12 cups of normal coffee, use 63.6 g of grounds.'
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`, `:normal`, and `:weak`, but you can use whatever you'd like.
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
- normal: 200,
74
- weak: 100
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: :weak, units: CorgeUnit.new)
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
- Clone the repo and run `rake test`.
106
+ * Fork/clone the repo
107
+ * `bundle install`
108
+ * `bundle exec rspec`
86
109
 
87
110
  ## Contributing
88
111
 
data/bin/console ADDED
@@ -0,0 +1,6 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require 'pry'
4
+ require 'pot_of_coffee'
5
+
6
+ Pry.start
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: :normal,
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 (normal, strong, weak)') do |v|
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
- 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
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' ) do
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
@@ -10,7 +10,7 @@ module PotOfCoffee
10
10
 
11
11
  class WrongStrengthError < CoffeeError
12
12
  def message
13
- 'Sorry: coffee strength must be strong, normal, or weak'
13
+ 'Sorry: coffee strength must be strong, medium, or mild'
14
14
  end
15
15
  end
16
16
  end
@@ -11,8 +11,8 @@ module PotOfCoffee
11
11
 
12
12
  def table
13
13
  {
14
- weak: 0.5,
15
- normal: 0.675,
14
+ mild: 0.5,
15
+ medium: 0.675,
16
16
  strong: 0.875,
17
17
  }
18
18
  end
@@ -11,8 +11,8 @@ module PotOfCoffee
11
11
 
12
12
  def table
13
13
  {
14
- weak: 2,
15
- normal: 4.16,
14
+ mild: 2,
15
+ medium: 4.16,
16
16
  strong: 5.3
17
17
  }
18
18
  end
@@ -1,3 +1,3 @@
1
1
  module PotOfCoffee
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
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
@@ -21,4 +21,5 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency 'bundler', '~> 1.7'
22
22
  spec.add_development_dependency 'rake', '~> 10.0'
23
23
  spec.add_development_dependency 'rspec', '~> 3.6.0'
24
+ spec.add_development_dependency 'pry', '~> 0.11'
24
25
  end
@@ -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('To make 12 cups of of normal coffee, use 8.1 tbsp of grounds.')
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(:normal)
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
- normal: 279.10,
39
- weak: 100
38
+ medium: 279.10,
39
+ mild: 100
40
40
  }
41
41
  end
42
42
  end
43
43
 
44
- let(:units) { WhateverUnit.new }
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('To make 12 cups of of normal coffee, use 3349.2 gb of grounds.')
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, :normal, :strong].each { |key| t.keys.include?(key) } } }
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.2.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-28 00:00:00.000000000 Z
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.5.1
117
+ rubygems_version: 2.6.8
102
118
  signing_key:
103
119
  specification_version: 4
104
120
  summary: Coffee brew strength calculator