gravitheque 0.4.0 → 0.5.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.
@@ -1,71 +0,0 @@
1
- require "conversions/extract"
2
- require "conversions/volume"
3
-
4
- module Calculate
5
-
6
- # Calculates the number of yeast cells needed to properly ferment a batch.
7
- # Supported extract units are `:brix`, `:plato` and `:specific_gravity`. Default: `:plato`
8
- # Supported beers types are `:ale`, `:hybrid` and `:lager`. Default: `:ale`
9
- # Supported volume units are `:gallons` and `:liters`. Default: `:liters`
10
- #
11
- # @example
12
- # Calculate.yeast_cells_required({
13
- # extract: 16.5,
14
- # volume: 19
15
- # })
16
- #
17
- # Calculate.yeast_cells_required({
18
- # extract: 15.75,
19
- # volume: 5.25
20
- # }, { volume: :gallons })
21
- #
22
- # Calculate.yeast_cells_required({
23
- # extract: 1.055,
24
- # volume: 55
25
- # }, { extract: :specific_gravity })
26
- #
27
- # Calculate.yeast_cells_required({
28
- # extract: 18,
29
- # volume: 20,
30
- # type: :hybrid
31
- # })
32
- #
33
- # Calculate.yeast_cells_required({
34
- # extract: 21.5,
35
- # volume: 10.5,
36
- # type: :lager
37
- # }, { volume: :gallons, extract: :brix })
38
- #
39
- # @param [Hash] data data required to calculate yeast cells required; `extract`, `volume`, `type`
40
- # @param [Float] volume liters of wort being pitched
41
- # @param [Hash] options used to change default settings for `extract`, `volume` and `type`
42
- # @return [Fixnum] yeast cells needed to ferment the batch
43
- def self.yeast_cells_required data, units = {}
44
- data.merge!(:type => :ale) unless data[:type]
45
- units.merge!(:extract => :plato) unless units[:extract]
46
- units.merge!(:volume => :liters) unless units[:volume]
47
-
48
- cells_per_milliliter = case data[:type]
49
- when :ale then 750_000
50
- when :hybrid then 1_125_000
51
- when :lager then 1_500_000
52
- else raise ArgumentError, "#{data[:type]} is an unknown type of beer. Use :ale, :hybrid or :lager"
53
- end
54
-
55
- volume = case units[:volume]
56
- when :liters then data[:volume]
57
- when :gallons then Convert.gallons_to_liters data[:volume]
58
- else raise ArgumentError, "#{units[:volume]} is an unknown unit of volume. Use :gallons or :liters"
59
- end
60
-
61
- extract = case units[:extract]
62
- when :plato then data[:extract]
63
- when :brix then Convert.specific_gravity_to_plato(Convert.brix_to_specific_gravity data[:extract])
64
- when :specific_gravity then Convert.specific_gravity_to_plato data[:extract]
65
- else raise ArgumentError, "#{units[:extract]} is an unknown unit of extract. Use :brix, :plato or :specific_gravity"
66
- end
67
-
68
- (cells_per_milliliter * (volume * 1000) * extract).round
69
- end
70
-
71
- end
@@ -1,8 +0,0 @@
1
- require "conversions/extract"
2
- require "conversions/mass"
3
- require "conversions/temperature"
4
- require "conversions/volume"
5
-
6
- # Convert between different units of things.
7
- module Convert
8
- end
@@ -1,99 +0,0 @@
1
- require "conversions/temperature"
2
-
3
- module Convert
4
-
5
- # Convert specific gravity to degrees Plato.
6
- #
7
- # @example
8
- # Convert.specific_gravity_to_plato 1.055
9
- #
10
- # @param [Float] specific_gravity
11
- # @return [Float] degrees Plato
12
- def self.specific_gravity_to_plato specific_gravity
13
- specific_gravity = specific_gravity.to_f
14
-
15
- (-676.67 + 1286.4 * specific_gravity - 800.47 *
16
- specific_gravity * specific_gravity + 190.74 *
17
- specific_gravity * specific_gravity * specific_gravity).round 1
18
- end
19
-
20
- # Convert degrees Brix to specific gravity.
21
- # @note
22
- # This method is only for converting pre-fermentation degrees Brix to
23
- # specific gravity. To accurately convert a terminal Brix reading to
24
- # terminal gravity use the `terminal_brix_to_terminal_gravity` method.
25
- #
26
- # @example
27
- # Convert.brix_to_specific_gravity 14.2
28
- #
29
- # @param [Float] specific_gravity
30
- # @return [Float] degrees Plato
31
- def self.brix_to_specific_gravity brix
32
- (1.000898 + 0.003859118 * brix + 0.00001370735 *
33
- brix * brix + 0.00000003742517 * brix * brix * brix).round 3
34
- end
35
-
36
- # Convert terminal Brix to specific gravity.
37
- #
38
- # @example
39
- # Convert.terminal_brix_to_terminal_gravity 14.2, 7.4
40
- #
41
- # @param [Float] original the pre-fermentation Brix reading
42
- # @param [Float] terminal the post-fermentation Brix reading
43
- # @return [Float] the terminal gravity
44
- def self.terminal_brix_to_terminal_gravity original, terminal
45
- (1.001843 - (0.002318474 * original) -
46
- (0.000007775 * original * original) -
47
- (0.000000034 * original * original * original) +
48
- (0.00574 * terminal) +
49
- (0.00003344 * terminal * terminal) +
50
- (0.000000086 * terminal * terminal * terminal)).round 3
51
- end
52
-
53
- # Convert degrees Plato to specific gravity.
54
- #
55
- # @example
56
- # Convert.plato_to_specific_gravity 18.9
57
- #
58
- # @param [Float] degrees Plato
59
- # @return [Float] specific gravity
60
- def self.plato_to_specific_gravity plato
61
- (plato / (258.6 - ((plato / 258.2) * 227.1)) + 1.0).round 3
62
- end
63
-
64
- # Calculates the temperature corrected specific gravity.
65
- # Set the unit option to `:celsius` if your sample temperature is not Farhenheit.
66
- #
67
- # @example
68
- # Calculate.specific_gravity_to_temperature_corrected_gravity 1.013, 34
69
- # Calculate.specific_gravity_to_temperature_corrected_gravity 1.013, 4, :celsius
70
- #
71
- # @param [Float] gravity the measured specific gravity
72
- # @param [Float] temperature the temperature of the sample
73
- # @param [Symbol] unit the temperature measure used
74
- # @return [Float] the temperature corrected specific gravity
75
- def self.specific_gravity_to_temperature_corrected_gravity gravity, temperature, unit = :farhenheit
76
- unless unit == :farhenheit
77
- if unit == :celsius
78
- temperature = Convert.celsius_to_fahrenheit temperature
79
- else
80
- raise ArgumentError, "#{unit} is not recogized as a unit of measure"
81
- end
82
- end
83
-
84
- if temperature < 3.98
85
- correction = -0.000032692 * temperature - 0.000740644
86
- elsif temperature < 50
87
- correction = -0.0008031922 - 0.0000473773 * temperature +
88
- 0.000007231263 * temperature * temperature -
89
- 0.00000003078278 * temperature *
90
- temperature * temperature
91
- else
92
- correction = -0.005431719 + 0.0001963596 * temperature +
93
- 0.000002661056 * temperature * temperature
94
- end
95
-
96
- (gravity + correction).round 3
97
- end
98
-
99
- end
@@ -1,47 +0,0 @@
1
- module Convert
2
-
3
- # Convert grams to ounces.
4
- #
5
- # @example
6
- # Convert.grams_to_ounces 56
7
- #
8
- # @param [Float] grams
9
- # @return [Float] mass in ounces
10
- def self.grams_to_ounces grams
11
- (grams * 0.0352739619).round 1
12
- end
13
-
14
- # Convert ounces to grams.
15
- #
16
- # @example
17
- # Convert.ounces_to_grams 3
18
- #
19
- # @param [Float] ounces
20
- # @return [Float] mass in grams
21
- def self.ounces_to_grams ounces
22
- (ounces * 28.3495231).round 1
23
- end
24
-
25
- # Convert kilograms to pounds.
26
- #
27
- # @example
28
- # Convert.kilograms_to_pounds 15
29
- #
30
- # @param [Float] kilograms
31
- # @return [Float] mass in pounds
32
- def self.kilograms_to_pounds kilograms
33
- (kilograms * 2.204623).round 1
34
- end
35
-
36
- # Convert pounds to kilograms.
37
- #
38
- # @example
39
- # Convert.pounds_to_kilograms 19
40
- #
41
- # @param [Float] pounds
42
- # @return [Float] mass in kilograms
43
- def self.pounds_to_kilograms pounds
44
- (pounds * 0.453592).round 1
45
- end
46
-
47
- end
@@ -1,25 +0,0 @@
1
- module Convert
2
-
3
- # Convert Celsius to Fahrenheit.
4
- #
5
- # @example
6
- # Convert.celsius_to_fahrenheit 24
7
- #
8
- # @param [Float] celsius
9
- # @return [Float] temperature in Fahrenheit
10
- def self.celsius_to_fahrenheit celsius
11
- ((celsius * 1.8) + 32).round 1
12
- end
13
-
14
- # Convert Fahrenheit to Celsius.
15
- #
16
- # @example
17
- # Convert.fahrenheit_to_celsius 175
18
- #
19
- # @param [Float] fahrenheit
20
- # @return [Float] temperature in Celsius
21
- def self.fahrenheit_to_celsius fahrenheit
22
- ((fahrenheit - 32) / 1.8).round 1
23
- end
24
-
25
- end
@@ -1,47 +0,0 @@
1
- module Convert
2
-
3
- # Convert gallons to liters.
4
- #
5
- # @example
6
- # Convert.gallons_to_liters 52
7
- #
8
- # @param [Float] gallons
9
- # @return [Float] volume in liters
10
- def self.gallons_to_liters gallons
11
- (gallons * 3.785412).round 1
12
- end
13
-
14
- # Convert liters to gallons.
15
- #
16
- # @example
17
- # Convert.liters_to_gallons 36
18
- #
19
- # @param [Float] liters
20
- # @return [Float] volume in gallons
21
- def self.liters_to_gallons liters
22
- (liters * 0.264172052).round 1
23
- end
24
-
25
- # Convert liters to quarts.
26
- #
27
- # @example
28
- # Convert.liters_to_quarts 9
29
- #
30
- # @param [Float] liters
31
- # @return [Float] volume in quarts
32
- def self.liters_to_quarts liters
33
- (liters * 1.056688).round 1
34
- end
35
-
36
- # Convert quarts to liters.
37
- #
38
- # @example
39
- # Convert.quarts_to_liters 23
40
- #
41
- # @param [Float] quarts
42
- # @return [Float] volume in liters
43
- def self.quarts_to_liters quarts
44
- (quarts * 0.946353).round 1
45
- end
46
-
47
- end
@@ -1,2 +0,0 @@
1
- require_relative "calculators"
2
- require_relative "conversions"
@@ -1,58 +0,0 @@
1
- require "./test/test_helper"
2
- require "calculators/alcohol"
3
-
4
- describe Calculate do
5
-
6
- it "must calculate alcohol by weight from original and terminal Plato" do
7
- Calculate.alcohol_by_weight({ original: 13, terminal: 2.5 }).must_equal 4.5
8
- end
9
-
10
- it "must calculate alcohol by weight from original and terminal gravities" do
11
- Calculate.alcohol_by_weight({
12
- original: 1.055,
13
- terminal: 1.011
14
- }, :specific_gravity).must_equal 4.6
15
- end
16
-
17
- it "must calculate alcohol by weight from original and terminal Brix" do
18
- Calculate.alcohol_by_weight({
19
- original: 15.5,
20
- terminal: 7.2
21
- }, :brix).must_equal 5.9
22
- end
23
-
24
- it "must calculate alcohol by volume from original and terminal Plato" do
25
- Calculate.alcohol_by_volume({ original: 13, terminal: 2.5 }).must_equal 5.7
26
- end
27
-
28
- it "must calculate alcohol by volume from original and terminal gravities" do
29
- Calculate.alcohol_by_volume({
30
- original: 1.055,
31
- terminal: 1.011
32
- }, :specific_gravity).must_equal 5.8
33
- end
34
-
35
- it "must calculate alcohol by volume from original and terminal Brix" do
36
- Calculate.alcohol_by_volume({
37
- original: 15.5,
38
- terminal: 7.2
39
- }, :brix).must_equal 7.4
40
- end
41
-
42
- it "must raise an exception when the extract unit is unrecognized" do
43
- lambda {
44
- Calculate.alcohol_by_volume({
45
- original: 392,
46
- terminal: 739
47
- }, :wtf)
48
- }.must_raise ArgumentError
49
-
50
- lambda {
51
- Calculate.alcohol_by_weight({
52
- original: 392,
53
- terminal: 739
54
- }, :wtf)
55
- }.must_raise ArgumentError
56
- end
57
-
58
- end
@@ -1,89 +0,0 @@
1
- require "./test/test_helper"
2
- require "calculators/calories"
3
-
4
- describe Calculate do
5
-
6
- it "must calculate calories from alcohol using original and terminal Plato" do
7
- Calculate.calories_from_alcohol({ original: 13, terminal: 2.5 }).must_equal 151
8
- end
9
-
10
- it "must calculate calories from alcohol using original and terminal gravities" do
11
- Calculate.calories_from_alcohol({
12
- original: 1.05,
13
- terminal: 1.01
14
- }, :specific_gravity).must_equal 139
15
- end
16
-
17
- it "must calculate calories from alcohol using original and terminal Brix" do
18
- Calculate.calories_from_alcohol({
19
- original: 15.5,
20
- terminal: 7.2
21
- }, :brix).must_equal 202
22
- end
23
-
24
- it "must calculate calories from extract using original and terminal Plato" do
25
- Calculate.calories_from_extract({
26
- original: 13,
27
- terminal: 2.5
28
- }).must_equal 83
29
- end
30
-
31
- it "must calculate calories from extract using original and terminal gravities" do
32
- Calculate.calories_from_extract({
33
- original: 1.05,
34
- terminal: 1.01
35
- }, :specific_gravity).must_equal 80
36
- end
37
-
38
- it "must calculate calories from extract using original and terminal Brix" do
39
- Calculate.calories_from_extract({
40
- original: 15.5,
41
- terminal: 7.2
42
- }, :brix).must_equal 80
43
- end
44
-
45
- it "must calculate calories per serving using original and terminal Plato" do
46
- Calculate.calories_per_serving({
47
- original: 13,
48
- terminal: 2.5
49
- }).must_equal 234
50
- end
51
-
52
- it "must calculate calories per serving using original and terminal gravities" do
53
- Calculate.calories_per_serving({
54
- original: 1.05,
55
- terminal: 1.01
56
- }, :specific_gravity).must_equal 219
57
- end
58
-
59
- it "must calculate calories per serving using original and terminal Brix" do
60
- Calculate.calories_per_serving({
61
- original: 15.5,
62
- terminal: 7.2
63
- }, :brix).must_equal 282
64
- end
65
-
66
- it "must raise an exception when the extract unit is unrecognized" do
67
- lambda {
68
- Calculate.calories_from_alcohol({
69
- original: 392,
70
- terminal: 739
71
- }, :wtf)
72
- }.must_raise ArgumentError
73
-
74
- lambda {
75
- Calculate.calories_from_extract({
76
- original: 392,
77
- terminal: 739
78
- }, :wtf)
79
- }.must_raise ArgumentError
80
-
81
- lambda {
82
- Calculate.calories_per_serving({
83
- original: 392,
84
- terminal: 739
85
- }, :wtf)
86
- }.must_raise ArgumentError
87
- end
88
-
89
- end