beer_recipe 0.4.11 → 0.4.13

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: 37e343ebd5dd90883f61380871711d71725d2fc3
4
- data.tar.gz: b064a9d35839ef3fc97220ccbd07f60d2f1aa3f8
3
+ metadata.gz: b1c69aef39b81784e559ab44b4c5bd5b6a372971
4
+ data.tar.gz: 81c43a22d05f859b7ebf5c0f49e65c6123cd4532
5
5
  SHA512:
6
- metadata.gz: 98d7349d9ba872c49a932a20e19df6ad1a83d3b375a80272bd4119bd1c4ce7b858c10d64fe96e362669bb83bd4ed9431e3b916f2c8ca1d7a7b6c67e717025352
7
- data.tar.gz: 1887c8480321e2dd989a419ae3e2cfa334d3e3e5e71aa786dfc0899e0997caafc9e77292ba0461fc3a1885e1d3d28ce260d2e830c3a0cd3fedb61f085e07b64f
6
+ metadata.gz: eb7bb97935f5d937c226bf73fec7d5af7904b551f02fa01b08432dd024c0c21dbc253d8263fd622ed186dae27f0c92bfa0fd8d8673164e3ee640892c1549eec1
7
+ data.tar.gz: b98e1f9b232315b238f67ab508321064115de97f20ab950abae49cb49e3426ee266e9b903d0d35f549ba2e2558b6e2596db37c7794930e5245f824186112bfb2
@@ -6,12 +6,14 @@ class BeerRecipe::MashWrapper < BeerRecipe::Wrapper
6
6
  end
7
7
 
8
8
  def steps
9
+ return [] if @record.nil?
9
10
  @steps ||= @record.mash_steps.map do |step|
10
11
  BeerRecipe::Wrapper.wrap(step, @recipe)
11
12
  end
12
13
  end
13
14
 
14
15
  def total_mash_time
16
+ return 0 if steps.empty?
15
17
  steps.map { |s| s.step_time || 0 }.reduce :+ || 0
16
18
  end
17
19
  end
@@ -1,8 +1,9 @@
1
1
  class BeerRecipe::RecipeWrapper < BeerRecipe::Wrapper
2
2
  SETS = %i(fermentables hops miscs waters yeasts)
3
3
 
4
- def initialize(record, recipe=nil)
5
- super
4
+ def initialize(record, actual_values: false)
5
+ super(record)
6
+ @actual_values = actual_values
6
7
  @sets = {}
7
8
  end
8
9
 
@@ -62,20 +63,40 @@ class BeerRecipe::RecipeWrapper < BeerRecipe::Wrapper
62
63
  strip_unit(recipe.est_fg)
63
64
  end
64
65
 
66
+ def actual_og
67
+ recipe.og
68
+ end
69
+
70
+ def actual_fg
71
+ recipe.fg
72
+ end
73
+
65
74
  def og
66
- @og ||= estimated_og || recipe.og || 0
75
+ @og ||= @actual_values && actual_og > 0 ? actual_og : estimated_og || 0
67
76
  end
68
77
 
69
78
  def fg
70
- @fg ||= estimated_fg || recipe.fg || 0
79
+ @fg ||= @actual_values && actual_fg > 0 ? actual_fg : estimated_fg || 0
80
+ end
81
+
82
+ def actual_abv
83
+ strip_unit(recipe.abv)
84
+ end
85
+
86
+ def estimated_abv
87
+ strip_unit(recipe.est_abv)
88
+ end
89
+
90
+ def calculated_abv
91
+ BeerRecipe::Formula.new.sg_to_abv(og, fg)
71
92
  end
72
93
 
73
94
  def abv
74
- @abv ||= BeerRecipe::Formula.new.sg_to_abv(og, fg)
95
+ @abv ||= @actual_values && actual_abv > 0 ? actual_abv : estimated_abv || calculated_abv
75
96
  end
76
97
 
77
98
  def ibu
78
- @ibu ||= strip_unit(recipe.ibu) || calculate_ibu
99
+ @ibu ||= @actual_values && calculated_ibu > 0 ? calculated_ibu : estimated_ibu
79
100
  end
80
101
 
81
102
  def strip_unit(value)
@@ -83,15 +104,21 @@ class BeerRecipe::RecipeWrapper < BeerRecipe::Wrapper
83
104
  value.gsub(/ \w+\Z/, '').to_f
84
105
  end
85
106
 
86
- def calculate_ibu
87
- ibu = 0
88
- hops.each do |hop|
89
- ibu += hop.ibu
90
- end
91
- bitter_extracts.each do |f|
92
- ibu += f.ibu
107
+ def estimated_ibu
108
+ strip_unit(recipe.ibu)
109
+ end
110
+
111
+ def calculated_ibu
112
+ @calculated_ibu ||= begin
113
+ ibu = 0
114
+ hops.each do |hop|
115
+ ibu += hop.ibu
116
+ end
117
+ bitter_extracts.each do |f|
118
+ ibu += f.ibu
119
+ end
120
+ ibu
93
121
  end
94
- ibu
95
122
  end
96
123
 
97
124
  def grains
@@ -102,8 +129,16 @@ class BeerRecipe::RecipeWrapper < BeerRecipe::Wrapper
102
129
  fermentables.select { |f| f.bitter_extract? }
103
130
  end
104
131
 
132
+ def estimated_color
133
+ strip_unit(recipe.est_color)
134
+ end
135
+
105
136
  def color
106
- color_srm
137
+ @actual_values ? actual_color : estimated_color
138
+ end
139
+
140
+ def actual_color
141
+ color_ebc
107
142
  end
108
143
 
109
144
  def color_mcu
@@ -119,7 +154,7 @@ class BeerRecipe::RecipeWrapper < BeerRecipe::Wrapper
119
154
  end
120
155
 
121
156
  def color_ebc
122
- @color_eb ||= BeerRecipe::Formula.new.srm_to_ebc(color_srm)
157
+ @color_ebc ||= BeerRecipe::Formula.new.srm_to_ebc(color_srm)
123
158
  end
124
159
 
125
160
  def color_class
@@ -138,7 +173,7 @@ class BeerRecipe::RecipeWrapper < BeerRecipe::Wrapper
138
173
  end
139
174
 
140
175
  def formatted_color
141
- "#{'%.0f' % color_ebc} EBC"
176
+ "#{'%.0f' % color} EBC"
142
177
  end
143
178
 
144
179
  def total_grains
@@ -181,7 +216,15 @@ class BeerRecipe::RecipeWrapper < BeerRecipe::Wrapper
181
216
 
182
217
  # Returns calories per liter
183
218
  def calories
184
- @calories ||= if has_final_values?
219
+ @calories ||= @actual_values && calculated_calories > 0 ? calculated_calories : estimated_calories
220
+ end
221
+
222
+ def estimated_calories
223
+ strip_unit(recipe.calories)
224
+ end
225
+
226
+ def calculated_calories
227
+ if has_final_values?
185
228
  BeerRecipe::Formula.new.calories(serving_size, abv, og, fg)
186
229
  else
187
230
  0
@@ -189,7 +232,7 @@ class BeerRecipe::RecipeWrapper < BeerRecipe::Wrapper
189
232
  end
190
233
 
191
234
  def real_extract
192
- @real_extract ||= if og > 0 && fg > 0
235
+ @real_extract ||= if has_final_values?
193
236
  BeerRecipe::Formula.new.real_extract(og, fg)
194
237
  else
195
238
  0
@@ -1,3 +1,3 @@
1
1
  module BeerRecipe
2
- VERSION = '0.4.11'
2
+ VERSION = '0.4.13'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beer_recipe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.11
4
+ version: 0.4.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Olle Johansson
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  version: '0'
116
116
  requirements: []
117
117
  rubyforge_project:
118
- rubygems_version: 2.2.2
118
+ rubygems_version: 2.5.2
119
119
  signing_key:
120
120
  specification_version: 4
121
121
  summary: Simple Beer XML recipe formatter.