gravitheque 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/.travis.yml +8 -0
- data/.yardopts +1 -0
- data/Gemfile +14 -0
- data/Guardfile +5 -0
- data/LICENSE +22 -0
- data/README.md +111 -0
- data/bin/test +8 -0
- data/gravitheque.gemspec +15 -0
- data/lib/calculators/alcohol.rb +58 -0
- data/lib/calculators/calories.rb +97 -0
- data/lib/calculators.rb +6 -0
- data/lib/conversions/extract.rb +97 -0
- data/lib/conversions/mass.rb +47 -0
- data/lib/conversions/temperature.rb +25 -0
- data/lib/conversions/volume.rb +47 -0
- data/lib/conversions.rb +8 -0
- data/lib/gravitheque.rb +2 -0
- data/test/calculators/test_alcohol.rb +35 -0
- data/test/calculators/test_calories.rb +48 -0
- data/test/conversions/test_extract.rb +26 -0
- data/test/conversions/test_mass.rb +22 -0
- data/test/conversions/test_temperature.rb +18 -0
- data/test/conversions/test_volume.rb +22 -0
- data/test/test_helper.rb +3 -0
- metadata +78 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--markup=markdown - LICENSE
|
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright 2012, john muhl
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without modification,
|
5
|
+
are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
* Redistributions of source code must retain the above copyright notice, this
|
8
|
+
list of conditions and the following disclaimer.
|
9
|
+
* Redistributions in binary form must reproduce the above copyright notice, this
|
10
|
+
list of conditions and the following disclaimer in the documentation and/or
|
11
|
+
other materials provided with the distribution.
|
12
|
+
|
13
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
14
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
15
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
16
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
17
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
18
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
19
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
20
|
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
21
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
22
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
# Gravitheque [![Build Status](https://secure.travis-ci.org/johnmuhl/gravitheque.png)](http://travis-ci.org/johnmuhl/gravitheque)
|
2
|
+
|
3
|
+
A collection of [open source][oss] tools for brewers. It can be used as
|
4
|
+
a [web application][web], interactively through IRB or as a [library][lib] to
|
5
|
+
build your own brewing application. For use as a library refer the full
|
6
|
+
[documentation][doc].
|
7
|
+
|
8
|
+
## Calculators
|
9
|
+
|
10
|
+
### Alcohol
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
require "calculators/alcohol"
|
14
|
+
|
15
|
+
Calculate.alcohol_by_volume 12, 4
|
16
|
+
Calculate.alcohol_by_volume 1.055, 1.012, :specific_gravity
|
17
|
+
Calculate.alcohol_by_volume 16.4, 8.2, :brix
|
18
|
+
|
19
|
+
Calculate.alcohol_by_weight 12, 4
|
20
|
+
Calculate.alcohol_by_weight 1.055, 1.012, :specific_gravity
|
21
|
+
Calculate.alcohol_by_weight 16.4, 8.2, :brix
|
22
|
+
```
|
23
|
+
|
24
|
+
### Calories
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
require "calculators/calories"
|
28
|
+
|
29
|
+
Calculate.calories_from_alcohol 12, 4
|
30
|
+
Calculate.calories_from_alcohol 1.055, 1.012, :specific_gravity
|
31
|
+
Calculate.calories_from_alcohol 16.4, 8.2, :brix
|
32
|
+
|
33
|
+
Calculate.calories_from_extract 12, 4
|
34
|
+
Calculate.calories_from_extract 1.055, 1.012, :specific_gravity
|
35
|
+
Calculate.calories_from_extract 16.4, 8.2, :brix
|
36
|
+
|
37
|
+
Calculate.calories_per_serving 12, 4
|
38
|
+
Calculate.calories_per_serving 1.055, 1.012, :specific_gravity
|
39
|
+
Calculate.calories_per_serving 16.4, 8.2, :brix
|
40
|
+
```
|
41
|
+
|
42
|
+
### Yeast
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
require "calculators/yeast"
|
46
|
+
|
47
|
+
Calculate.yeast_cells_required 16.5, 5.25
|
48
|
+
Calculate.yeast_cells_required 15.75, 19, { :batch_size => :liters }
|
49
|
+
Calculate.yeast_cells_required 1.055, 55, { :extract => :specific_gravity }
|
50
|
+
Calculate.yeast_cells_required 18, 10.75, { :type => :hybrid }
|
51
|
+
Calculate.yeast_cells_required 21.5, 100, { :batch_size => :liters, :extract => :brix, :type => :lager }
|
52
|
+
```
|
53
|
+
|
54
|
+
## Conversions
|
55
|
+
|
56
|
+
### Extract
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
require "conversions/extract"
|
60
|
+
|
61
|
+
Convert.brix_to_specific_gravity 14.2
|
62
|
+
|
63
|
+
Convert.terminal_brix_to_terminal_gravity 16.2, 7.8
|
64
|
+
|
65
|
+
Convert.plato_to_specific_gravity 16
|
66
|
+
|
67
|
+
Convert.specific_gravity_to_plato 1.055
|
68
|
+
```
|
69
|
+
|
70
|
+
### Mass
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
require "conversions/mass"
|
74
|
+
|
75
|
+
Convert.grams_to_ounces 30
|
76
|
+
|
77
|
+
Convert.ounces_to_grams 3
|
78
|
+
|
79
|
+
Convert.kilograms_to_pounds 15
|
80
|
+
|
81
|
+
Convert.pounds_to_kilograms 8
|
82
|
+
```
|
83
|
+
|
84
|
+
### Temperature
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
require "conversions/temperature"
|
88
|
+
|
89
|
+
Convert.celsius_to_fahrenheit 25
|
90
|
+
|
91
|
+
Convert.farhenheit_to_celsius 154
|
92
|
+
```
|
93
|
+
|
94
|
+
### Volumes
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
require "conversions/volumes"
|
98
|
+
|
99
|
+
Convert.gallons_to_liters 8
|
100
|
+
|
101
|
+
Convert.liters_to_gallons 23
|
102
|
+
|
103
|
+
Convert.liters_to_quarts 5
|
104
|
+
|
105
|
+
Convert.quarts_to_liters 11
|
106
|
+
```
|
107
|
+
|
108
|
+
[doc]: http://rubydoc.info/gems/gravitheque
|
109
|
+
[lib]: http://rubygems.org/gems/gravitheque
|
110
|
+
[oss]: https://github.com/johnmuhl/gravitheque/blob/master/LICENSE
|
111
|
+
[web]: http://gravitheque.herokuapp.com/
|
data/bin/test
ADDED
data/gravitheque.gemspec
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.authors = ["john muhl"]
|
5
|
+
gem.email = ["git@johnmuhl.com"]
|
6
|
+
gem.description = "Tools for brewers."
|
7
|
+
gem.summary = "The library that will eventually power the web application of the same name."
|
8
|
+
gem.homepage = "http://gravitheque.herokuapp.com/"
|
9
|
+
|
10
|
+
gem.files = `git ls-files`.split("\n")
|
11
|
+
gem.test_files = `git ls-files -- test/*`.split("\n")
|
12
|
+
gem.name = "gravitheque"
|
13
|
+
gem.require_paths = ["lib"]
|
14
|
+
gem.version = "0.1.0"
|
15
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require "conversions/extract"
|
2
|
+
|
3
|
+
module Calculate
|
4
|
+
|
5
|
+
# Calculates alcohol by weight given original and terminal extract levels.
|
6
|
+
# Set the `unit` option for extract levels that are not degrees Plato.
|
7
|
+
# Other supported units are `:specific_gravity` and `:brix`.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# Calculate.alcohol_by_weight 17.5, 3.2
|
11
|
+
# Calculate.alcohol_by_weight 1.055, 1.010, :specific_gravity
|
12
|
+
# Calculate.alcohol_by_weight 15.2, 7.8, :brix
|
13
|
+
#
|
14
|
+
# @param [Float] original the original extract level
|
15
|
+
# @param [Float] terminal the terminal extract level
|
16
|
+
# @param [Symbol] unit the unit used to measure extract
|
17
|
+
# @return [Float] the alcohol content by weight
|
18
|
+
def self.alcohol_by_weight original, terminal, unit = :plato
|
19
|
+
original = original.to_f
|
20
|
+
terminal = terminal.to_f
|
21
|
+
|
22
|
+
unless unit == :plato
|
23
|
+
case unit
|
24
|
+
when :specific_gravity
|
25
|
+
original = Convert.specific_gravity_to_plato original
|
26
|
+
terminal = Convert.specific_gravity_to_plato terminal
|
27
|
+
when :brix
|
28
|
+
og = Convert.brix_to_specific_gravity original
|
29
|
+
tg = Convert.terminal_brix_to_terminal_gravity original, terminal
|
30
|
+
original = Convert.specific_gravity_to_plato og
|
31
|
+
terminal = Convert.specific_gravity_to_plato tg
|
32
|
+
else
|
33
|
+
raise ArgumentError, "#{unit} is not recogized as a unit of measure"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
((original - ((0.1808 * original) + (0.8192 * terminal))) /
|
38
|
+
(2.0665 - (0.010665 * original))).round 1
|
39
|
+
end
|
40
|
+
|
41
|
+
# Calculates alcohol by volume given original and terminal extract levels.
|
42
|
+
# Set the `unit` option for extract levels that are not degrees Plato.
|
43
|
+
# Other supported units are `:specific_gravity` and `:brix`.
|
44
|
+
#
|
45
|
+
# @example
|
46
|
+
# Calculate.alcohol_by_volume 17.5, 3.2
|
47
|
+
# Calculate.alcohol_by_volume 1.055, 1.010, :specific_gravity
|
48
|
+
# Calculate.alcohol_by_volume 15.2, 7.8, :brix
|
49
|
+
#
|
50
|
+
# @param [Float] original the original extract level
|
51
|
+
# @param [Float] terminal the terminal extract level
|
52
|
+
# @param [Symbol] unit the unit used to measure extract
|
53
|
+
# @return [Float] the alcohol content by volume
|
54
|
+
def self.alcohol_by_volume original, terminal, unit = :plato
|
55
|
+
((alcohol_by_weight original, terminal, unit) / 0.793573).round 1
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require "conversions/extract"
|
2
|
+
|
3
|
+
module Calculate
|
4
|
+
|
5
|
+
# Calculates calories derived from alcohol content.
|
6
|
+
# Set the `unit` option for extract levels that are not degrees Plato.
|
7
|
+
# Other supported units are `:specific_gravity` and `:brix`.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# Calculate.calories_from_alcohol 17.5, 3.2
|
11
|
+
# Calculate.calories_from_alcohol 1.055, 1.010, :specific_gravity
|
12
|
+
# Calculate.calories_from_alcohol 15.2, 7.8, :brix
|
13
|
+
#
|
14
|
+
# @param [Float] original the original extract level
|
15
|
+
# @param [Float] terminal the terminal extract level
|
16
|
+
# @param [Symbol] unit the unit used to measure extract
|
17
|
+
# @return [Fixnum] the total calories from alcohol per 500ml
|
18
|
+
def self.calories_from_alcohol original, terminal, unit = :plato
|
19
|
+
original = original.to_f
|
20
|
+
terminal = terminal.to_f
|
21
|
+
|
22
|
+
unless unit == :specific_gravity
|
23
|
+
case unit
|
24
|
+
when :brix
|
25
|
+
original = Convert.brix_to_specific_gravity original
|
26
|
+
terminal = Convert.terminal_brix_to_terminal_gravity original, terminal
|
27
|
+
when :plato
|
28
|
+
original = Convert.plato_to_specific_gravity original
|
29
|
+
terminal = Convert.plato_to_specific_gravity terminal
|
30
|
+
else
|
31
|
+
raise ArgumentError, "#{unit} is not recogized as a unit of measure"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
calories = (1881.22 * terminal) *
|
36
|
+
((original - terminal) /
|
37
|
+
(1.775 - original))
|
38
|
+
|
39
|
+
(calories + (calories * 0.33)).round
|
40
|
+
end
|
41
|
+
|
42
|
+
# Calculates calories derived from extract.
|
43
|
+
# Set the `unit` option for extract levels that are not degrees Plato.
|
44
|
+
# Other supported units are `:specific_gravity` and `:brix`.
|
45
|
+
#
|
46
|
+
# @example
|
47
|
+
# Calculate.calories_from_extract 17.5, 3.2
|
48
|
+
# Calculate.calories_from_extract 1.055, 1.010, :specific_gravity
|
49
|
+
# Calculate.calories_from_extract 15.2, 7.8, :brix
|
50
|
+
#
|
51
|
+
# @param [Float] original the original extract level
|
52
|
+
# @param [Float] terminal the terminal extract level
|
53
|
+
# @param [Symbol] unit the unit used to measure extract
|
54
|
+
# @return [Fixnum] the total calories from extract per 500ml
|
55
|
+
def self.calories_from_extract original, terminal, unit = :plato
|
56
|
+
original = original.to_f
|
57
|
+
terminal = terminal.to_f
|
58
|
+
|
59
|
+
unless unit == :specific_gravity
|
60
|
+
case unit
|
61
|
+
when :brix
|
62
|
+
original = Convert.brix_to_specific_gravity original
|
63
|
+
terminal = Convert.terminal_brix_to_terminal_gravity original, terminal
|
64
|
+
when :plato
|
65
|
+
original = Convert.plato_to_specific_gravity original
|
66
|
+
terminal = Convert.plato_to_specific_gravity terminal
|
67
|
+
else
|
68
|
+
raise ArgumentError, "#{unit} is not recogized as a unit of measure"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
calories = 3550.0 * terminal *
|
73
|
+
((0.1808 * original) +
|
74
|
+
(0.8192 * terminal) - 1.0004)
|
75
|
+
|
76
|
+
(calories + (calories * 0.33)).round
|
77
|
+
end
|
78
|
+
|
79
|
+
# Calculates total calories per serving.
|
80
|
+
# Set the `unit` option for extract levels that are not degrees Plato.
|
81
|
+
# Other supported units are `:specific_gravity` and `:brix`.
|
82
|
+
#
|
83
|
+
# @example
|
84
|
+
# Calculate.calories_per_serving 17.5, 3.2
|
85
|
+
# Calculate.calories_per_serving 1.055, 1.010, :specific_gravity
|
86
|
+
# Calculate.calories_per_serving 15.2, 7.8, :brix
|
87
|
+
#
|
88
|
+
# @param [Float] original the original extract level
|
89
|
+
# @param [Float] terminal the terminal extract level
|
90
|
+
# @param [Symbol] unit the unit used to measure extract
|
91
|
+
# @return [Fixnum] the total calories per 500ml
|
92
|
+
def self.calories_per_serving original, terminal, unit = :plato
|
93
|
+
(calories_from_alcohol original, terminal, unit) +
|
94
|
+
(calories_from_extract original, terminal, unit)
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
data/lib/calculators.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
module Convert
|
2
|
+
|
3
|
+
# Convert specific gravity to degrees Plato.
|
4
|
+
#
|
5
|
+
# @example
|
6
|
+
# Convert.specific_gravity_to_plato 1.055
|
7
|
+
#
|
8
|
+
# @param [Float] specific_gravity
|
9
|
+
# @return [Float] degrees Plato
|
10
|
+
def self.specific_gravity_to_plato specific_gravity
|
11
|
+
specific_gravity = specific_gravity.to_f
|
12
|
+
|
13
|
+
(-676.67 + 1286.4 * specific_gravity - 800.47 *
|
14
|
+
specific_gravity * specific_gravity + 190.74 *
|
15
|
+
specific_gravity * specific_gravity * specific_gravity).round 1
|
16
|
+
end
|
17
|
+
|
18
|
+
# Convert degrees Brix to specific gravity.
|
19
|
+
# @note
|
20
|
+
# This method is only for converting pre-fermentation degrees Brix to
|
21
|
+
# specific gravity. To accurately convert a terminal Brix reading to
|
22
|
+
# terminal gravity use the `terminal_brix_to_terminal_gravity` method.
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
# Convert.brix_to_specific_gravity 14.2
|
26
|
+
#
|
27
|
+
# @param [Float] specific_gravity
|
28
|
+
# @return [Float] degrees Plato
|
29
|
+
def self.brix_to_specific_gravity brix
|
30
|
+
(1.000898 + 0.003859118 * brix + 0.00001370735 *
|
31
|
+
brix * brix + 0.00000003742517 * brix * brix * brix).round 3
|
32
|
+
end
|
33
|
+
|
34
|
+
# Convert terminal Brix to specific gravity.
|
35
|
+
#
|
36
|
+
# @example
|
37
|
+
# Convert.terminal_brix_to_terminal_gravity 14.2, 7.4
|
38
|
+
#
|
39
|
+
# @param [Float] original the pre-fermentation Brix reading
|
40
|
+
# @param [Float] terminal the post-fermentation Brix reading
|
41
|
+
# @return [Float] the terminal gravity
|
42
|
+
def self.terminal_brix_to_terminal_gravity original, terminal
|
43
|
+
(1.001843 - (0.002318474 * original) -
|
44
|
+
(0.000007775 * original * original) -
|
45
|
+
(0.000000034 * original * original * original) +
|
46
|
+
(0.00574 * terminal) +
|
47
|
+
(0.00003344 * terminal * terminal) +
|
48
|
+
(0.000000086 * terminal * terminal * terminal)).round 3
|
49
|
+
end
|
50
|
+
|
51
|
+
# Convert degrees Plato to specific gravity.
|
52
|
+
#
|
53
|
+
# @example
|
54
|
+
# Convert.plato_to_specific_gravity 18.9
|
55
|
+
#
|
56
|
+
# @param [Float] degrees Plato
|
57
|
+
# @return [Float] specific gravity
|
58
|
+
def self.plato_to_specific_gravity plato
|
59
|
+
(plato / (258.6 - ((plato / 258.2) * 227.1)) + 1.0).round 3
|
60
|
+
end
|
61
|
+
|
62
|
+
# Calculates the temperature corrected specific gravity.
|
63
|
+
# Set the unit option to `:celsius` if your sample temperature is not Farhenheit.
|
64
|
+
#
|
65
|
+
# @example
|
66
|
+
# Calculate.specific_gravity_to_temperature_corrected_gravity 1.013, 34
|
67
|
+
# Calculate.specific_gravity_to_temperature_corrected_gravity 1.013, 4, :celsius
|
68
|
+
#
|
69
|
+
# @param [Float] gravity the measured specific gravity
|
70
|
+
# @param [Float] temperature the temperature of the sample
|
71
|
+
# @param [Symbol] unit the temperature measure used
|
72
|
+
# @return [Float] the temperature corrected specific gravity
|
73
|
+
def self.specific_gravity_to_temperature_corrected_gravity gravity, temperature, unit = :farhenheit
|
74
|
+
unless unit == :farhenheit
|
75
|
+
if unit == :celsius
|
76
|
+
temperature = Convert.celsius_to_fahrenheit temperature
|
77
|
+
else
|
78
|
+
raise ArgumentError, "#{unit} is not recogized as a unit of measure"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
if temperature < 3.98
|
83
|
+
correction = -0.000032692 * temperature - 0.000740644
|
84
|
+
elsif temperature < 50
|
85
|
+
correction = -0.0008031922 - 0.0000473773 * temperature +
|
86
|
+
0.000007231263 * temperature * temperature -
|
87
|
+
0.00000003078278 * temperature *
|
88
|
+
temperature * temperature
|
89
|
+
else
|
90
|
+
correction = -0.005431719 + 0.0001963596 * temperature +
|
91
|
+
0.000002661056 * temperature * temperature
|
92
|
+
end
|
93
|
+
|
94
|
+
(gravity + correction).round 3
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
@@ -0,0 +1,47 @@
|
|
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
|
@@ -0,0 +1,25 @@
|
|
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
|
@@ -0,0 +1,47 @@
|
|
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
|
data/lib/conversions.rb
ADDED
data/lib/gravitheque.rb
ADDED
@@ -0,0 +1,35 @@
|
|
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 13, 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 1.055, 1.011, :specific_gravity).must_equal 4.6
|
12
|
+
end
|
13
|
+
|
14
|
+
it "must calculate alcohol by weight from original and terminal Brix" do
|
15
|
+
(Calculate.alcohol_by_weight 15.5, 7.2, :brix).must_equal 5.9
|
16
|
+
end
|
17
|
+
|
18
|
+
it "must calculate alcohol by volume from original and terminal Plato" do
|
19
|
+
(Calculate.alcohol_by_volume 13, 2.5).must_equal 5.7
|
20
|
+
end
|
21
|
+
|
22
|
+
it "must calculate alcohol by volume from original and terminal gravities" do
|
23
|
+
(Calculate.alcohol_by_volume 1.055, 1.011, :specific_gravity).must_equal 5.8
|
24
|
+
end
|
25
|
+
|
26
|
+
it "must calculate alcohol by volume from original and terminal Brix" do
|
27
|
+
(Calculate.alcohol_by_volume 15.5, 7.2, :brix).must_equal 7.4
|
28
|
+
end
|
29
|
+
|
30
|
+
it "must raise an exception when the extract unit is unrecognized" do
|
31
|
+
lambda { Calculate.alcohol_by_volume 392, 739, :wtf? }.must_raise ArgumentError
|
32
|
+
lambda { Calculate.alcohol_by_weight 392, 739, :wtf? }.must_raise ArgumentError
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,48 @@
|
|
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 13, 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 1.05, 1.01, :specific_gravity).must_equal 139
|
12
|
+
end
|
13
|
+
|
14
|
+
it "must calculate calories from alcohol using original and terminal Brix" do
|
15
|
+
(Calculate.calories_from_alcohol 15.5, 7.2, :brix).must_equal 81
|
16
|
+
end
|
17
|
+
|
18
|
+
it "must calculate calories from extract using original and terminal Plato" do
|
19
|
+
(Calculate.calories_from_extract 13, 2.5).must_equal 83
|
20
|
+
end
|
21
|
+
|
22
|
+
it "must calculate calories from extract using original and terminal gravities" do
|
23
|
+
(Calculate.calories_from_extract 1.05, 1.01, :specific_gravity).must_equal 80
|
24
|
+
end
|
25
|
+
|
26
|
+
it "must calculate calories from extract using original and terminal Brix" do
|
27
|
+
(Calculate.calories_from_extract 15.5, 7.2, :brix).must_equal 224
|
28
|
+
end
|
29
|
+
|
30
|
+
it "must calculate calories per serving using original and terminal Plato" do
|
31
|
+
(Calculate.calories_per_serving 13, 2.5).must_equal 234
|
32
|
+
end
|
33
|
+
|
34
|
+
it "must calculate calories per serving using original and terminal gravities" do
|
35
|
+
(Calculate.calories_per_serving 1.05, 1.01, :specific_gravity).must_equal 219
|
36
|
+
end
|
37
|
+
|
38
|
+
it "must calculate calories per serving using original and terminal Brix" do
|
39
|
+
(Calculate.calories_per_serving 15.5, 7.2, :brix).must_equal 305
|
40
|
+
end
|
41
|
+
|
42
|
+
it "must raise an exception when the extract unit is unrecognized" do
|
43
|
+
lambda { Calculate.calories_from_alcohol 392, 739, :wtf? }.must_raise ArgumentError
|
44
|
+
lambda { Calculate.calories_from_extract 392, 739, :wtf? }.must_raise ArgumentError
|
45
|
+
lambda { Calculate.calories_per_serving 392, 739, :wtf? }.must_raise ArgumentError
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "./test/test_helper"
|
2
|
+
require "conversions/extract"
|
3
|
+
|
4
|
+
describe Convert do
|
5
|
+
|
6
|
+
it "must convert specific gravity to Plato" do
|
7
|
+
(Convert.specific_gravity_to_plato 1.055).must_equal 13.5
|
8
|
+
end
|
9
|
+
|
10
|
+
it "must convert Brix to specific gravity" do
|
11
|
+
(Convert.brix_to_specific_gravity 16.2).must_equal 1.067
|
12
|
+
end
|
13
|
+
|
14
|
+
it "must convert terminal Brix to terminal gravity" do
|
15
|
+
(Convert.terminal_brix_to_terminal_gravity 16.2, 7.8).must_equal 1.009
|
16
|
+
end
|
17
|
+
|
18
|
+
it "must convert Plato to specific gravity" do
|
19
|
+
(Convert.plato_to_specific_gravity 18.9).must_equal 1.078
|
20
|
+
end
|
21
|
+
|
22
|
+
it "must convert specific gravity to temperature corrected specific gravity" do
|
23
|
+
(Convert.specific_gravity_to_temperature_corrected_gravity 1.064, 42).must_equal 1.072
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "./test/test_helper"
|
2
|
+
require "conversions/mass"
|
3
|
+
|
4
|
+
describe Convert do
|
5
|
+
|
6
|
+
it "must convert grams to ounces" do
|
7
|
+
(Convert.grams_to_ounces 56).must_equal 2.0
|
8
|
+
end
|
9
|
+
|
10
|
+
it "must convert ounces to grams" do
|
11
|
+
(Convert.ounces_to_grams 2).must_equal 56.7
|
12
|
+
end
|
13
|
+
|
14
|
+
it "must convert kilograms to pounds" do
|
15
|
+
(Convert.kilograms_to_pounds 10).must_equal 22.0
|
16
|
+
end
|
17
|
+
|
18
|
+
it "must convert pounds to kilograms" do
|
19
|
+
(Convert.pounds_to_kilograms 10).must_equal 4.5
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "./test/test_helper"
|
2
|
+
require "conversions/temperature"
|
3
|
+
|
4
|
+
describe Convert do
|
5
|
+
|
6
|
+
it "must convert Celsius to Fahrenheit" do
|
7
|
+
(Convert.celsius_to_fahrenheit 0).must_equal 32.0
|
8
|
+
(Convert.celsius_to_fahrenheit 50).must_equal 122.0
|
9
|
+
(Convert.celsius_to_fahrenheit 100).must_equal 212.0
|
10
|
+
end
|
11
|
+
|
12
|
+
it "must convert Fahrenheit to Celsius" do
|
13
|
+
(Convert.fahrenheit_to_celsius 32).must_equal 0.0
|
14
|
+
(Convert.fahrenheit_to_celsius 90).must_equal 32.2
|
15
|
+
(Convert.fahrenheit_to_celsius 212).must_equal 100.0
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "./test/test_helper"
|
2
|
+
require "conversions/volume"
|
3
|
+
|
4
|
+
describe Convert do
|
5
|
+
|
6
|
+
it "must convert gallons to liters" do
|
7
|
+
(Convert.gallons_to_liters 5).must_equal 18.9
|
8
|
+
end
|
9
|
+
|
10
|
+
it "must convert liters to gallons" do
|
11
|
+
(Convert.liters_to_gallons 19).must_equal 5.0
|
12
|
+
end
|
13
|
+
|
14
|
+
it "must convert liters to quarts" do
|
15
|
+
(Convert.liters_to_quarts 19).must_equal 20.1
|
16
|
+
end
|
17
|
+
|
18
|
+
it "must convert quarts to liters" do
|
19
|
+
(Convert.quarts_to_liters 20).must_equal 18.9
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gravitheque
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- john muhl
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-23 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Tools for brewers.
|
15
|
+
email:
|
16
|
+
- git@johnmuhl.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- .travis.yml
|
23
|
+
- .yardopts
|
24
|
+
- Gemfile
|
25
|
+
- Guardfile
|
26
|
+
- LICENSE
|
27
|
+
- README.md
|
28
|
+
- bin/test
|
29
|
+
- gravitheque.gemspec
|
30
|
+
- lib/calculators.rb
|
31
|
+
- lib/calculators/alcohol.rb
|
32
|
+
- lib/calculators/calories.rb
|
33
|
+
- lib/conversions.rb
|
34
|
+
- lib/conversions/extract.rb
|
35
|
+
- lib/conversions/mass.rb
|
36
|
+
- lib/conversions/temperature.rb
|
37
|
+
- lib/conversions/volume.rb
|
38
|
+
- lib/gravitheque.rb
|
39
|
+
- test/calculators/test_alcohol.rb
|
40
|
+
- test/calculators/test_calories.rb
|
41
|
+
- test/conversions/test_extract.rb
|
42
|
+
- test/conversions/test_mass.rb
|
43
|
+
- test/conversions/test_temperature.rb
|
44
|
+
- test/conversions/test_volume.rb
|
45
|
+
- test/test_helper.rb
|
46
|
+
homepage: http://gravitheque.herokuapp.com/
|
47
|
+
licenses: []
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
none: false
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
none: false
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.8.15
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: The library that will eventually power the web application of the same name.
|
70
|
+
test_files:
|
71
|
+
- test/calculators/test_alcohol.rb
|
72
|
+
- test/calculators/test_calories.rb
|
73
|
+
- test/conversions/test_extract.rb
|
74
|
+
- test/conversions/test_mass.rb
|
75
|
+
- test/conversions/test_temperature.rb
|
76
|
+
- test/conversions/test_volume.rb
|
77
|
+
- test/test_helper.rb
|
78
|
+
has_rdoc:
|