Class: ProMashTxt::Recipe

Inherits:
Brewser::Recipe show all
Defined in:
lib/brewser/engines/promash_txt.rb

Instance Method Summary collapse

Methods inherited from Brewser::Recipe

#as_json, json_create

Methods inherited from Brewser::Model

#as_beerxml, #as_brewson, auto_migrate_down!, auto_migrate_up!, auto_upgrade!, default_repository_name

Instance Method Details

#from_promash(array) ⇒ Object

Raises:

  • (Error)


147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/brewser/engines/promash_txt.rb', line 147

def from_promash(array)
  self.name=array[0]
  self.style=ProMashTxt::Style.new.from_promash(array)
  # Recipe specifics should look like this:
  # Recipe Specifics
  # ----------------
  # Batch Size (Gal):         6.00    Wort Size (Gal):    6.00
  # Total Grain (Lbs):       12.00
  # Anticipated OG:          1.059    Plato:             14.52
  # Anticipated SRM:          11.0
  # Anticipated IBU:          53.5
  # Brewhouse Efficiency:       80 %
  # Wort Boil Time:             60    Minutes
  # Can't tell the difference between P/M and A/G so use A/G
  raise Error, "ProMashTxt engine: Unable to find recipe specifics" unless pointer = array.index("Recipe Specifics")
  self.method = /Total Grain/.match(array[pointer+3]).nil? ? "Extract" : "All Grain"
  /Batch Size \((?<volume_unit>\w+)\):\s*(?<batch_size>\S*)\s*Wort Size \(\w*\):\s*(?<boil_size>\S*)/.match(array[pointer+2]) do |match|
    self.recipe_volume = "#{match[:batch_size]} #{match[:volume_unit].downcase}".u
    self.boil_volume = "#{match[:boil_size]} #{match[:volume_unit].downcase}".u
  end
  /Anticipated OG:\s*(?<anticipated_og>\S*)/.match(array[pointer+4]) do |match|
    self.estimated_og = match[:anticipated_og].to_f
  end
  /Anticipated SRM:\s*(?<anticipated_color>\S*)/.match(array[pointer+5]) do |match|
    self.estimated_color = match[:anticipated_color].to_f
  end
  /Anticipated IBU:\s*(?<anticipated_ibu>\S*)/.match(array[pointer+6]) do |match|
    self.estimated_ibu = match[:anticipated_ibu].to_f
  end
  if method == "All Grain"
    /Brewhouse Efficiency:\s*(?<recipe_efficiency>\S*)/.match(array[pointer+7]) do |match|
      self.recipe_efficiency = match[:recipe_efficiency].to_f
    end
    boil_time_pointer = pointer+8
  else
    boil_time_pointer = pointer+7
  end
  /Wort Boil Time:\s*(?<boil_time>\S*)/.match(array[boil_time_pointer]) do |match|
    self.boil_time = "#{match[:boil_time]} min".u
  end
  
  hops_start = array.index("Hops")+3
  hops_end = (array.index("Extras") || array.index("Yeast"))-1
  array[hops_start..hops_end].each do |hop|
    self.hops.push ProMashTxt::Hop.new.from_promash(hop)
  end
  
  fermentables_start = array.index("Grain/Extract/Sugar")+3
  fermentables_end = array.index("Hops")-2
  array[fermentables_start..fermentables_end].each do |fermentable|
    self.fermentables.push ProMashTxt::Fermentable.new.from_promash(fermentable)
  end
  
  unless array.index("Extras").nil?
    additives_start = array.index("Extras")+3
    additives_end = array.index("Yeast")-1
    array[additives_start..additives_end].each do |additive|
      self.additives.push ProMashTxt::Additive.new.from_promash(additive)
    end
  end
  
  self.yeasts.push ProMashTxt::Yeast.new.from_promash(array[array.index("Yeast")+2])
  self.water_profile = ProMashTxt::WaterProfile.new.from_promash(array[array.index("Water Profile")+2,array.index("Water Profile")+10])
  
  return self
end