Class: Brewer::Recipe

Inherits:
Object
  • Object
show all
Defined in:
lib/brewer/recipe.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#varsObject

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_tempObject

: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_varsObject

: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

  using_message("Name this recipe: ").ask_for("name")
  using_message("Amount of water in quarts: ").ask_for("water")
  using_message("Amount of grain in lbs: ").ask_for("grain")
  using_message("Current grain temp (#{@controller.pv.to_s} F): ").ask_for("grain_temp", default: @controller.pv)
  using_message("Desired mash temp (150 F): ").ask_for("desired_mash_temp", default: 150)
  using_message("Mash temperature: ").ask_for("mash_temp")
  using_message("Mash time in minutes (60): ").ask_for("mash_time", default: 60)
  using_message("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

#nameObject



26
27
28
# File 'lib/brewer/recipe.rb', line 26

def name
  return @vars['name'] if @vars['name']
end

#typecast_varsObject



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 using_message(message)
  raise "Message needs to be a string" unless message.is_a? String
  print message
  self
end