pot_of_coffee 0.0.2 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c737bb79b74044f92383833c7640131dcfa03522
4
- data.tar.gz: 9792a23a844be2faf6fe460fb9e3f809084e0716
3
+ metadata.gz: 59a334e469e37a0e133e778526d8a8b38ef395da
4
+ data.tar.gz: 461e37e68c299d442826130f84d1079f9577184c
5
5
  SHA512:
6
- metadata.gz: 1fe29369cce46158e413f3d40c99caf3890bedba7e0008b1e621c3bb20dfbfa8638bcf2626780d0f6a5f4ef8228888ba120b14fd5c95ba041eb6633798ce81f8
7
- data.tar.gz: bddb3be88b3adfcc9dc0db2cc84b8e89324a89201992c62d526ddfba3e513ca0a1429c8632c3be234341232f1d54455dd19240c0de120daa2306c406d46a1cf3
6
+ metadata.gz: 84cb6d8a8e2a5559369f59d06a4b92c9d804f3219bcc117c8c89d8cec5aac4acfba105f7a251dc28aa86cb83ce2b471e7b033d2625be205169086f06af66821f
7
+ data.tar.gz: c89fe94927ddce0d9604b44a427dc45be34c10c4dcaa521760e5b86dd75e2caadee92291822ad65b1854a6d0d4f43512d935ef4ff66df0d6768b1bed2e466640
data/README.md CHANGED
@@ -32,6 +32,10 @@ pot_of_coffee = PotOfCoffee::Brewer.new(quantity: 12, strength: 'weak')
32
32
  pot_of_coffee.scoops # 6.0
33
33
  ```
34
34
 
35
+ ## Tests
36
+
37
+ Clone the repo and run `rake test`. The test coverage is *very basic*.
38
+
35
39
  ## Contributing
36
40
 
37
41
  1. Fork it ( https://github.com/[my-github-username]/pot_of_coffee/fork )
data/bin/pot_of_coffee CHANGED
@@ -7,5 +7,9 @@ unless ARGV[0] && ARGV[1]
7
7
  exit 1
8
8
  end
9
9
 
10
- pot_of_coffee = PotOfCoffee::Brewer.new(quantity: ARGV[0], strength: ARGV[1])
11
- puts "Number of scoops needed: #{pot_of_coffee.scoops}"
10
+ quantity = ARGV[0].to_i
11
+ strength = ARGV[1].to_sym
12
+ units = PotOfCoffee::MetricUnit.new
13
+
14
+ pot_of_coffee = PotOfCoffee::Brewer.new(quantity: quantity, strength: strength, units: units)
15
+ puts pot_of_coffee.instructions
data/lib/pot_of_coffee.rb CHANGED
@@ -1,38 +1,45 @@
1
1
  require 'pot_of_coffee/version'
2
+ require 'pot_of_coffee/units'
3
+ require 'pot_of_coffee/errors'
4
+ require 'forwardable'
2
5
 
3
6
  module PotOfCoffee
4
7
  class Brewer
5
- # Magic numbers omg
6
- RATIOS = {
7
- weak: 0.5,
8
- normal: 0.675,
9
- extra: 0.875,
10
- turbo: 1,
11
- starbucks: 2, # This is really how strong Starbucks expects someone to brew their coffe
12
- wtf: 3.8
13
- }
8
+ extend Forwardable
9
+ attr_reader :units
14
10
 
15
- attr_reader :ratios, :strength, :quantity
11
+ def_delegator :@units, :table, :ratios
16
12
 
17
- def initialize(quantity: 12, strength: :normal)
18
- @quantity = quantity.to_i
19
- @strength = strength.to_sym
20
- @scoops = scoops
13
+ def initialize(args = {})
14
+ @quantity = args[:quantity] || 12
15
+ @strength = args[:strength] || :normal
16
+ @units = args[:units] || ImperialUnit.new
21
17
  end
22
18
 
23
- def ratios
24
- @ratios = RATIOS
19
+ def quantity
20
+ if @quantity > 0
21
+ @quantity
22
+ else
23
+ raise NegativeNumberError
24
+ end
25
25
  end
26
26
 
27
- def self.ratios
28
- RATIOS
27
+ def strength
28
+ if ratios.include?(@strength.to_sym)
29
+ @strength
30
+ else
31
+ raise WrongStrengthError
32
+ end
29
33
  end
30
34
 
31
- def scoops
35
+ def amount
32
36
  (quantity * ratios.fetch(strength)).round(2)
33
- rescue KeyError
34
- "I don't know how to make '#{strength}' strength coffee, sorry. Available options are #{ratios.keys.join(', ')}"
35
37
  end
36
38
 
39
+ def instructions
40
+ "To make #{quantity} cups of of #{strength} coffee, use #{amount} #{units.abbreviation} of grounds."
41
+ rescue NegativeNumberError, WrongStrengthError => e
42
+ print e.message
43
+ end
37
44
  end
38
- end
45
+ end
@@ -0,0 +1,16 @@
1
+ module PotOfCoffee
2
+ class CoffeeError < StandardError
3
+ end
4
+
5
+ class NegativeNumberError < CoffeeError
6
+ def message
7
+ 'Sorry: coffee quantity must be greater than 0'
8
+ end
9
+ end
10
+
11
+ class WrongStrengthError < CoffeeError
12
+ def message
13
+ 'Sorry: coffee strength must be strong, normal, or weak'
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,43 @@
1
+ module PotOfCoffee
2
+ class Unit
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
12
+
13
+ def abbreviation
14
+ 'tbsp'
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: 12,
38
+ normal: 20,
39
+ strong: 28,
40
+ }
41
+ end
42
+ end
43
+ end
@@ -1,3 +1,3 @@
1
1
  module PotOfCoffee
2
- VERSION = '0.0.2'
2
+ VERSION = '0.1.0'
3
3
  end
data/test/helper.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/pride'
3
+ require 'pot_of_coffee'
@@ -0,0 +1,28 @@
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
@@ -0,0 +1,21 @@
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 240.0 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
@@ -0,0 +1,17 @@
1
+ class WhateverUnit
2
+ def name
3
+ 'grably'
4
+ end
5
+
6
+ def abbreviation
7
+ 'gb'
8
+ end
9
+
10
+ def table
11
+ {
12
+ strong: 109109,
13
+ normal: 279.10,
14
+ weak: 100
15
+ }
16
+ end
17
+ 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.0.2
4
+ version: 0.1.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: 2015-05-19 00:00:00.000000000 Z
11
+ date: 2016-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -68,9 +68,14 @@ files:
68
68
  - Rakefile
69
69
  - bin/pot_of_coffee
70
70
  - lib/pot_of_coffee.rb
71
+ - lib/pot_of_coffee/errors.rb
72
+ - lib/pot_of_coffee/units.rb
71
73
  - lib/pot_of_coffee/version.rb
72
74
  - pot_of_coffee.gemspec
73
- - test/test_pot_of_coffee.rb
75
+ - test/helper.rb
76
+ - test/test_brewer.rb
77
+ - test/test_units.rb
78
+ - test/whatever_unit.rb
74
79
  homepage: http://daveshaffer.co/coffee
75
80
  licenses:
76
81
  - MIT
@@ -91,9 +96,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
96
  version: '0'
92
97
  requirements: []
93
98
  rubyforge_project:
94
- rubygems_version: 2.4.6
99
+ rubygems_version: 2.4.5.1
95
100
  signing_key:
96
101
  specification_version: 4
97
102
  summary: Coffee brew strength calculator
98
103
  test_files:
99
- - test/test_pot_of_coffee.rb
104
+ - test/helper.rb
105
+ - test/test_brewer.rb
106
+ - test/test_units.rb
107
+ - test/whatever_unit.rb
@@ -1,26 +0,0 @@
1
- require 'minitest/autorun' # Because testing should happen
2
- require 'minitest/pride' # Because testing should be fabulous
3
- require 'pot_of_coffee'
4
-
5
- class PotOfCoffeeTest < Minitest::Test
6
- def setup
7
- options = { quantity: rand(24), strength: PotOfCoffee::Brewer.ratios.keys.sample }
8
- @pot_of_coffee = PotOfCoffee::Brewer.new(options)
9
- end
10
-
11
- def test_ratios
12
- assert_kind_of Hash, PotOfCoffee::Brewer.ratios
13
- end
14
-
15
- def test_strength
16
- assert_includes @pot_of_coffee.ratios, @pot_of_coffee.strength
17
- end
18
-
19
- def test_quantity
20
- assert_kind_of Integer, @pot_of_coffee.quantity
21
- end
22
-
23
- def test_scoops
24
- assert_kind_of Float, @pot_of_coffee.scoops
25
- end
26
- end