Class: Brewer::Recipe
- Inherits:
-
Object
- Object
- Brewer::Recipe
- Defined in:
- lib/brewer/recipe.rb
Instance Attribute Summary collapse
-
#vars ⇒ Object
Returns the value of attribute vars.
Instance Method Summary collapse
- #ask_for(var, default: nil) ⇒ Object
-
#calculate_strike_temp ⇒ Object
:nocov:.
-
#get_recipe_vars ⇒ Object
:nocov:.
-
#initialize(name = nil, blank: false) ⇒ Recipe
constructor
A new instance of Recipe.
- #load(recipe) ⇒ Object
- #name ⇒ Object
- #typecast_vars ⇒ Object
-
#using_message(message) ⇒ Object
:nocov:.
Constructor Details
#initialize(name = nil, blank: false) ⇒ Recipe
Returns a new instance of Recipe.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/brewer/recipe.rb', line 8 def initialize(name=nil, blank: false) @controller = Controller.new @vars = {} if blank return true end if name load(name) return true else get_recipe_vars typecast_vars end end |
Instance Attribute Details
#vars ⇒ Object
Returns the value of attribute vars.
6 7 8 |
# File 'lib/brewer/recipe.rb', line 6 def vars @vars end |
Instance Method Details
#ask_for(var, default: nil) ⇒ Object
64 65 66 67 68 |
# File 'lib/brewer/recipe.rb', line 64 def ask_for(var, default: nil) @vars[var] = default input = gets.chomp.strip @vars[var] = input if !input.empty? end |
#calculate_strike_temp ⇒ Object
:nocov:
53 54 55 |
# File 'lib/brewer/recipe.rb', line 53 def calculate_strike_temp @vars['strike_water_temp'] = @controller.script('get_strike_temp', "#{@vars['water']} #{@vars['grain']} #{@vars['grain_temp']} #{@vars['desired_mash_temp']}").to_f end |
#get_recipe_vars ⇒ Object
:nocov:
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/brewer/recipe.rb', line 35 def get_recipe_vars puts Rainbow("Creating a new recipe").green ("Name this recipe: ").ask_for("name") ("Amount of water in quarts: ").ask_for("water") ("Amount of grain in lbs: ").ask_for("grain") ("Current grain temp (#{@controller.pv.to_s} F): ").ask_for("grain_temp", default: @controller.pv) ("Desired mash temp (150 F): ").ask_for("desired_mash_temp", default: 150) ("Mash temperature: ").ask_for("mash_temp") ("Mash time in minutes (60): ").ask_for("mash_time", default: 60) ("Mashout temp: ").ask_for("mashout_temp") @vars['mash_time'] = to_seconds(@vars['mash_time']) true end |
#load(recipe) ⇒ Object
30 31 32 |
# File 'lib/brewer/recipe.rb', line 30 def load(recipe) @vars = YAML.load(File.open(kitchen_dir(recipe) + ".yml")) end |
#name ⇒ Object
26 27 28 |
# File 'lib/brewer/recipe.rb', line 26 def name return @vars['name'] if @vars['name'] end |
#typecast_vars ⇒ Object
70 71 72 73 74 75 |
# File 'lib/brewer/recipe.rb', line 70 def typecast_vars @vars.each do |key, value| # All values in @vars should be floats @vars[key] = value.to_f if key != "name" end end |
#using_message(message) ⇒ Object
:nocov:
58 59 60 61 62 |
# File 'lib/brewer/recipe.rb', line 58 def () raise "Message needs to be a string" unless .is_a? String print self end |