Class: BreadCalculator::Summary

Inherits:
Recipe
  • Object
show all
Defined in:
lib/bread_calculator.rb

Overview

This class represents a summary of a Recipe - like a Recipe, but:

Ingredients will be unitless and the quantities expressed in baker’s percentages,

Metadata will include baker’s percentages of flours, liquids, and additives.

Instance Attribute Summary

Attributes inherited from Recipe

#metadata, #steps

Instance Method Summary collapse

Methods inherited from Recipe

#bakers_percent, #bakers_percent_formula, #ingredients, #scale_by

Constructor Details

#initialize(metadata, steps) ⇒ Summary

Returns a new instance of Summary.



297
298
299
# File 'lib/bread_calculator.rb', line 297

def initialize , steps
  super
end

Instance Method Details

#recipe(weight, units = 'grams') ⇒ Object



326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# File 'lib/bread_calculator.rb', line 326

def recipe weight, units='grams'
  
   = self..reject{|k,v| k.to_s =~ /^total_/}

  totals = self..select{|k,v| k.to_s =~ /^total_/}
  all_totals = totals.values.inject(:+).to_f
  new_bp_100 = weight / all_totals
  
  new_steps = self.steps.map do |s| 
    step_args = s.techniques.map do |t| 
      t.is_a?(Ingredient) ? t.scale_by(new_bp_100, units) : t
    end
    Step.new step_args
  end

  Recipe.new , new_steps
  
end

#summaryObject



305
306
307
# File 'lib/bread_calculator.rb', line 305

def summary
  self
end

#to_htmlObject



321
322
323
324
# File 'lib/bread_calculator.rb', line 321

def to_html
  #FIXME obviously inadequate
  super
end

#to_sObject



309
310
311
312
313
314
315
316
317
318
319
# File 'lib/bread_calculator.rb', line 309

def to_s
  #FIXME this should be calling super somehow
  out = ''
  self..each do |k,v| 
    nv =  k.to_s =~ /^total_/ ? "#{human_round(v*100).to_s}%" : v
    out << "#{k}: #{nv}\n"
  end
  out << "--------------------\n"
  self.steps.each{|s| out << s.to_s(:summary)}
  out
end

#weightObject



301
302
303
# File 'lib/bread_calculator.rb', line 301

def weight
  nil
end