Class: BreadCalculator::Summary
- 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
Instance Method Summary collapse
-
#initialize(metadata, steps) ⇒ Summary
constructor
A new instance of Summary.
- #recipe(weight, units = 'grams') ⇒ Object
- #summary ⇒ Object
- #to_html ⇒ Object
- #to_s ⇒ Object
- #weight ⇒ Object
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 |
#summary ⇒ Object
305 306 307 |
# File 'lib/bread_calculator.rb', line 305 def summary self end |
#to_html ⇒ Object
321 322 323 324 |
# File 'lib/bread_calculator.rb', line 321 def to_html #FIXME obviously inadequate super end |
#to_s ⇒ Object
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 |
#weight ⇒ Object
301 302 303 |
# File 'lib/bread_calculator.rb', line 301 def weight nil end |