gravitheque 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,115 +0,0 @@
1
- require "conversions/extract"
2
-
3
- module Calculate
4
-
5
- # Calculates calories derived from alcohol content.
6
- # Supported extract units are `:brix`, `:plato` and `:specific_gravity`. Default: `:plato`
7
- #
8
- # @example
9
- # Calculate.calories_from_alcohol({ original: 17.5, terminal: 3.2 })
10
- #
11
- # Calculate.calories_from_alcohol({
12
- # original: 1.055,
13
- # terminal: 1.010
14
- # }, :specific_gravity)
15
- #
16
- # Calculate.calories_from_alcohol({
17
- # original: 15.2,
18
- # terminal: 7.8
19
- # }, :brix)
20
- #
21
- # @param [Hash] extract the original and terminal extract levels
22
- # @param [Symbol] unit the unit used to measure extract
23
- # @return [Fixnum] the total calories from alcohol per 500ml
24
- def self.calories_from_alcohol extract, units = :plato
25
- original = extract[:original]
26
- terminal = extract[:terminal]
27
-
28
- unless units == :specific_gravity
29
- case units
30
- when :brix
31
- original = Convert.brix_to_specific_gravity extract[:original]
32
- terminal = Convert.terminal_brix_to_terminal_gravity extract[:original], extract[:terminal]
33
- when :plato
34
- original = Convert.plato_to_specific_gravity extract[:original]
35
- terminal = Convert.plato_to_specific_gravity extract[:terminal]
36
- else
37
- raise ArgumentError, "#{units} is an unknown unit of extract. Use :brix, :plato or :specific_gravity"
38
- end
39
- end
40
-
41
- calories = (1881.22 * terminal) *
42
- ((original - terminal) /
43
- (1.775 - original))
44
-
45
- (calories + (calories * 0.33)).round
46
- end
47
-
48
- # Calculates calories derived from extract.
49
- # Supported extract units are `:brix`, `:plato` and `:specific_gravity`. Default: `:plato`
50
- #
51
- # @example
52
- # Calculate.calories_from_extract({ original: 17.5, terminal: 3.2 })
53
- #
54
- # Calculate.calories_from_extract({
55
- # original: 1.055,
56
- # terminal: 1.010
57
- # }, :specific_gravity)
58
- #
59
- # Calculate.calories_from_extract({
60
- # original: 15.2,
61
- # terminal: 7.8
62
- # }, :brix)
63
- #
64
- # @param [Hash] extract the original and terminal extract levels
65
- # @param [Symbol] unit the unit used to measure extract
66
- # @return [Fixnum] the total calories from extract per 500ml
67
- def self.calories_from_extract extract, units = :plato
68
- original = extract[:original]
69
- terminal = extract[:terminal]
70
-
71
- unless units == :specific_gravity
72
- case units
73
- when :brix
74
- original = Convert.brix_to_specific_gravity extract[:original]
75
- terminal = Convert.terminal_brix_to_terminal_gravity extract[:original], extract[:terminal]
76
- when :plato
77
- original = Convert.plato_to_specific_gravity extract[:original]
78
- terminal = Convert.plato_to_specific_gravity extract[:terminal]
79
- else
80
- raise ArgumentError, "#{units} is an unknown unit of extract. Use :brix, :plato or :specific_gravity"
81
- end
82
- end
83
-
84
- calories = 3550.0 * terminal *
85
- ((0.1808 * original) +
86
- (0.8192 * terminal) - 1.0004)
87
-
88
- (calories + (calories * 0.33)).round
89
- end
90
-
91
- # Calculates calories per serving.
92
- # Supported extract units are `:brix`, `:plato` and `:specific_gravity`. Default: `:plato`
93
- #
94
- # @example
95
- # Calculate.calories_per_serving({ original: 17.5, terminal: 3.2 })
96
- #
97
- # Calculate.calories_per_serving({
98
- # original: 1.055,
99
- # terminal: 1.010
100
- # }, :specific_gravity)
101
- #
102
- # Calculate.calories_per_serving({
103
- # original: 15.2,
104
- # terminal: 7.8
105
- # }, :brix)
106
- #
107
- # @param [Hash] extract the original and terminal extract levels
108
- # @param [Symbol] unit the unit used to measure extract
109
- # @return [Fixnum] the total calories per 500ml
110
- def self.calories_per_serving extract, units = :plato
111
- (calories_from_alcohol extract, units) +
112
- (calories_from_extract extract, units)
113
- end
114
-
115
- end
@@ -1,257 +0,0 @@
1
- require "conversions/extract"
2
- require "conversions/mass"
3
- require "conversions/volume"
4
-
5
- module Calculate
6
-
7
- # Calculates hop utilization.
8
- # Supported extract units are `:brix`, `:plato` and `:specific_gravity`. Default: `:plato`
9
- #
10
- # @example
11
- # Calculate.hop_utilization({ at: 20, extract: 12 })
12
- # Calculate.hop_utilization({ at: 20, extract: 12 }, :brix)
13
- # Calculate.hop_utilization({ at: 20, extract: 12 }, :specific_gravity)
14
- #
15
- # @param [Hash] data the extract level and time added
16
- # @param [Symbol] unit the unit used to measure extract
17
- # @return [Float] hop utilization
18
- def self.hop_utilization data, units = :plato
19
- unless units == :specific_gravity
20
- data[:extract] = case units
21
- when :brix then Convert.brix_to_specific_gravity data[:extract]
22
- when :plato then Convert.plato_to_specific_gravity data[:extract]
23
- else raise ArgumentError, "#{units} is an unknown unit of extract. Use :brix, :plato or :specific_gravity"
24
- end
25
- end
26
-
27
- ((hop_extract_adjustment data[:extract], :specific_gravity) *
28
- ((hop_boil_time_adjustment data[:at]) / 4.15)).round 2
29
- end
30
-
31
- # Calculates IBUs for hop addition.
32
- # Supported extract units are `:brix`, `:plato` and `:specific_gravity`. Default: `:plato`
33
- # Supported mass units are `:grams` and `:ounces`. Default: `:grams`
34
- # Supported volume units are `:gallons` and `:liters`. Default: `:liters`
35
- #
36
- # @example
37
- # Calculate.ibus({
38
- # alpha: 12.4,
39
- # at: 90,
40
- # extract: 15,
41
- # mass: 56,
42
- # volume: 20
43
- # })
44
- #
45
- # Calculate.ibus({
46
- # alpha: 6.5,
47
- # at: 60,
48
- # extract: 18.5,
49
- # mass: 30,
50
- # volume: 40
51
- # }, { extract: :brix })
52
- #
53
- # Calculate.ibus({
54
- # alpha: 8,
55
- # at: 30,
56
- # extract: 1.055,
57
- # mass: 3,
58
- # volume: 5
59
- # }, { extract: :specific_gravity, mass: :ounces, volume: :gallons })
60
- #
61
- # @param [Hash] data data required to calculate IBUs; `extract`, `alpha`, `at`, `mass`, `volume`
62
- # @param [Hash] units used to change default units for `extract`, `volume` and `mass`
63
- # @return [Fixnum] IBUs from hop addition
64
- def self.ibus data, units = {}
65
- units.merge!(extract: :plato) unless units[:extract]
66
- units.merge!(mass: :grams) unless units[:mass]
67
- units.merge!(volume: :liters) unless units[:volume]
68
-
69
- unless units[:extract] == :specific_gravity
70
- data[:extract] = case units[:extract]
71
- when :brix then Convert.brix_to_specific_gravity data[:extract]
72
- when :plato then Convert.plato_to_specific_gravity data[:extract]
73
- else raise ArgumentError, "#{units[:extract]} is an unknown unit of extract. Use :brix, :plato or :specific_gravity"
74
- end
75
- end
76
-
77
- unless units[:mass] == :grams
78
- data[:mass] = case units[:mass]
79
- when :ounces then Convert.ounces_to_grams data[:mass]
80
- else raise ArgumentError, "#{units[:mass]} is an unknown unit of mass. Use :grams or :ounces"
81
- end
82
- end
83
-
84
- unless units[:volume] == :liters
85
- data[:volume] = case units[:volume]
86
- when :gallons then Convert.gallons_to_liters data[:volume]
87
- else raise ArgumentError, "#{units[:volume]} is an unknown unit of volume. Use :gallons or :liters"
88
- end
89
- end
90
-
91
- (hop_extract_adjustment(data[:extract], :specific_gravity) *
92
- hop_boil_time_adjustment(data[:at]) * (data[:alpha] / 100) *
93
- data[:mass] * 1000 / (data[:volume] * 4.15)).round
94
- end
95
-
96
- # Calculates hop mass required to achieve specific IBUs.
97
- # Supported extract units are `:brix`, `:plato` and `:specific_gravity`. Default: `:plato`
98
- # Supported volume units are `:gallons` and `:liters`. Default: `:liters`
99
- #
100
- # @example
101
- # Calculate.hop_mass_required({
102
- # alpha: 13.5,
103
- # at: 60,
104
- # extract: 16,
105
- # ibus: 25,
106
- # volume: 20
107
- # })
108
- #
109
- # Calculate.hop_mass_required({
110
- # alpha: 3.2,
111
- # at: 15,
112
- # extract: 14.5,
113
- # ibus: 15,
114
- # volume: 20
115
- # }, { extract: :brix })
116
- #
117
- # Calculate.hop_mass_required({
118
- # alpha: 12.4,
119
- # at: 90,
120
- # extract: 1.05,
121
- # ibus: 100,
122
- # volume: 10
123
- # }, { extract: :specific_gravity, volume: :gallons })
124
- #
125
- # @param [Hash] data data required to calculate hop mass required; `extract`, `ibus`, `alpha`, `at`, `volume`
126
- # @param [Hash] units used to change default units for `extract` and `volume`
127
- # @return [Float] hop mass required to achieve specific IBUs
128
- def self.hop_mass_required data, units = {}
129
- units.merge!(extract: :plato) unless units[:extract]
130
- units.merge!(mass: :grams) unless units[:mass]
131
- units.merge!(volume: :liters) unless units[:volume]
132
-
133
- unless units[:extract] == :specific_gravity
134
- data[:extract] = case units[:extract]
135
- when :brix then Convert.brix_to_specific_gravity data[:extract]
136
- when :plato then Convert.plato_to_specific_gravity data[:extract]
137
- else raise ArgumentError, "#{units[:extract]} is an unknown unit of extract. Use :brix, :plato or :specific_gravity"
138
- end
139
- end
140
-
141
- unless units[:volume] == :liters
142
- data[:volume] = case units[:volume]
143
- when :gallons then Convert.gallons_to_liters data[:volume]
144
- else raise ArgumentError, "#{units[:volume]} is an unknown unit of volume. Use :gallons or :liters"
145
- end
146
- end
147
-
148
- mass = ((data[:volume] * data[:ibus]) /
149
- (hop_utilization({extract: data[:extract], at: data[:at]}, :specific_gravity) *
150
- data[:alpha] * 10))
151
-
152
- units[:mass] == :grams ? mass.round : Convert.grams_to_ounces(mass).round(1)
153
- end
154
-
155
- # Calculate milliliters of HopShot required to achieve specific IBUs.
156
- # Supported extract units are `:brix`, `:plato` and `:specific_gravity`. Default: `:plato`
157
- # Supported volume units are `:gallons` and `:liters`. Default: `:liters`
158
- #
159
- # @example
160
- # Calculate.hopshot_required({
161
- # alpha: 13.5,
162
- # at: 60,
163
- # extract: 16,
164
- # ibus: 25,
165
- # volume: 20
166
- # })
167
- #
168
- # Calculate.hopshot_required({
169
- # alpha: 3.2,
170
- # at: 15,
171
- # extract: 14.5,
172
- # ibus: 15,
173
- # volume: 20
174
- # }, { extract: :brix })
175
- #
176
- # Calculate.hopshot_required({
177
- # alpha: 12.4,
178
- # at: 90,
179
- # extract: 1.05,
180
- # ibus: 100,
181
- # volume: 10
182
- # }, { extract: :specific_gravity, volume: :gallons })
183
- #
184
- # @param [Hash] data data required to calculate hop mass required; `extract`, `ibus`, `at`, `volume`
185
- # @param [Hash] units used to change default units for `extract` and `volume`
186
- # @return [Float] milliliters of HopShot required to achieve specific IBUs
187
- def self.hopshot_required data, units = {}
188
- units.merge!(extract: :plato) unless units[:extract]
189
- units.merge!(volume: :liters) unless units[:volume]
190
-
191
- unless units[:extract] == :specific_gravity
192
- data[:extract] = case units[:extract]
193
- when :brix then Convert.brix_to_specific_gravity data[:extract]
194
- when :plato then Convert.plato_to_specific_gravity data[:extract]
195
- else raise ArgumentError, "#{units[:extract]} is an unknown unit of extract. Use :brix, :plato or :specific_gravity"
196
- end
197
- end
198
-
199
- unless units[:volume] == :liters
200
- data[:volume] = case units[:volume]
201
- when :gallons then Convert.gallons_to_liters data[:volume]
202
- else raise ArgumentError, "#{units[:volume]} is an unknown unit of volume. Use :liters or :gallons"
203
- end
204
- end
205
-
206
- unadjusted_amount = (data[:ibus] / 10.0) * (data[:volume] / 19.0)
207
- hopshot_required = unadjusted_amount
208
-
209
- if data[:extract] >= 1.08 && data[:extract] < 1.1
210
- hopshot_required = unadjusted_amount + (unadjusted_amount * 0.1)
211
- elsif data[:extract] >= 1.1 && data[:extract] < 1.15
212
- hopshot_required = unadjusted_amount + (unadjusted_amount * 0.2)
213
- elsif data[:extract] >= 1.15
214
- hopshot_required = unadjusted_amount + (unadjusted_amount * 0.3)
215
- end
216
-
217
- if data[:at] >= 90
218
- hopshot_required = hopshot_required - (unadjusted_amount * 0.1)
219
- end
220
-
221
- hopshot_required.round 1
222
- end
223
-
224
- # Calculate hop boil time adjustment.
225
- #
226
- # @example
227
- # Calculate.hop_boil_time_adjustment 60
228
- # Calculate.hop_boil_time_adjustment 15
229
- #
230
- # @param [Fixnum] at boil time remaining when hop addition is made
231
- # @return [Float] boil time adjustment
232
- def self.hop_boil_time_adjustment at
233
- (1 - Math.exp(-0.04 * at)).round 2
234
- end
235
-
236
- # Calculate hop extract adjustment.
237
- #
238
- # @example
239
- # Calculate.hop_extract_adjustment 12
240
- # Calculate.hop_extract_adjustment 14.2, :brix
241
- # Calculate.hop_extract_adjustment 1.065, :specific_gravity
242
- #
243
- # @param [Float] extract extract level when hop addition is made
244
- # @return [Float] extract adjustment
245
- def self.hop_extract_adjustment extract, units = :plato
246
- unless units == :specific_gravity
247
- extract = case units
248
- when :brix then Convert.brix_to_specific_gravity extract
249
- when :plato then Convert.plato_to_specific_gravity extract
250
- else raise ArgumentError, "#{units} is an unknown unit of extract. Use :brix, :plato or :specific_gravity"
251
- end
252
- end
253
-
254
- (1.65 * 0.000125 ** (extract - 1)).round 2
255
- end
256
-
257
- end
@@ -1,82 +0,0 @@
1
- module Calculate
2
-
3
- # Calculates temperature of strike water for dough in.
4
- # Supported units are `:metric` and `:us`. Default: `:metric`
5
- #
6
- # @example
7
- # Calculate.strike_temperature({
8
- # ratio: 1.5,
9
- # initial: 20,
10
- # target: 75
11
- # })
12
- #
13
- # Calculate.strike_temperature({
14
- # ratio: 1.25,
15
- # initial: 65,
16
- # target: 154
17
- # }, :us)
18
- #
19
- # Calculate.strike_temperature({
20
- # ratio: 1.5,
21
- # initial: 60,
22
- # target: 150,
23
- # loss: 1.015
24
- # }, :us)
25
- #
26
- # @param [Hash] data data required to calculate hop mass required; `ratio`, `initial`, `target`
27
- # @param [Symbol] units the unit used to measure temperature
28
- # @return [Fixnum] strike water temperature
29
- def self.strike_temperature data, units = :metric
30
- constant = case units
31
- when :metric then 0.41
32
- when :us then 0.2
33
- else raise ArgumentError, "#{units} is an unknown unit of measures. Use :metric or :us"
34
- end
35
-
36
- data.merge!(loss: 1) unless data[:loss]
37
-
38
- (((constant / data[:ratio]) *
39
- (data[:target] - data[:initial]) +
40
- data[:target]) * data[:loss]).round
41
- end
42
-
43
- # Calculates volume of boiling infusion water needed to increase mash temperature.
44
- # Supported units are `:metric` and `:us`. Default: `:metric`
45
- #
46
- # @example
47
- # Calculate.infusion_volume({
48
- # ratio: 1,
49
- # initial: 40,
50
- # target: 60,
51
- # mass: 3.6,
52
- # volume: 3.6
53
- # })
54
- #
55
- # Calculate.infusion_volume({
56
- # ratio: 1,
57
- # initial: 104,
58
- # target: 140,
59
- # mass: 8,
60
- # volume: 8
61
- # }, :us)
62
- #
63
- # @param [Hash] data data required to calculate infusion volume; `ratio`, `initial`, `target`, `mass`, `volume`
64
- # @param [Symbol] units the unit used for measurements
65
- # @return [Fixnum] infusion water volume
66
- def self.infusion_volume data, units = :metric
67
- case units
68
- when :metric
69
- boiling = 100
70
- constant = 0.41
71
- when :us
72
- boiling = 212
73
- constant = 0.2
74
- else raise ArgumentError, "#{units} is an unknown unit of measures. Use :metric or :us"
75
- end
76
-
77
- ((data[:target] - data[:initial]) *
78
- ((constant * data[:mass]) + data[:volume]) /
79
- (boiling - data[:target])).round 1
80
- end
81
-
82
- end