Class: BeerRecipe::HopWrapper

Inherits:
Wrapper
  • Object
show all
Defined in:
lib/beer_recipe/hop_wrapper.rb

Instance Method Summary collapse

Methods inherited from Wrapper

#blank?, #format_method, #initialize, #method_missing, #respond_to_missing?, set, wrap

Constructor Details

This class inherits a constructor from BeerRecipe::Wrapper

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class BeerRecipe::Wrapper

Instance Method Details

#aauObject



7
8
9
# File 'lib/beer_recipe/hop_wrapper.rb', line 7

def aau
  @record.alpha * amount * 0.035274
end

#adjust_bitterness(ibu) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/beer_recipe/hop_wrapper.rb', line 32

def adjust_bitterness(ibu)
  if @record.form == 'Pellet'
    ibu *= 1.10
  elsif @record.form == 'Plug'
    ibu *= 1.02
  end
  if @record.use == 'Mash'
    ibu *= 0.20
  elsif @record.use == 'First Wort'
    ibu *= 1.10
  elsif @record.use == 'Aroma'
    ibu *= 0.50
  end
  ibu
end

#amountObject



3
4
5
# File 'lib/beer_recipe/hop_wrapper.rb', line 3

def amount
  @record.amount * 1000
end

#amount_percentObject



92
93
94
# File 'lib/beer_recipe/hop_wrapper.rb', line 92

def amount_percent
  amount / @recipe.total_hops * 100
end

#boil_timeObject



60
61
62
63
64
65
66
# File 'lib/beer_recipe/hop_wrapper.rb', line 60

def boil_time
  if dryhop?
    0
  else
    @record.time / 60
  end
end

#calculate_ibuObject



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/beer_recipe/hop_wrapper.rb', line 20

def calculate_ibu
  # TODO: Use recipe boil time for first wort/mash
  # TODO: Use calculated_og if og missing.
  if has_needed_ibu_values? && contributes_bitterness?
    ibu = BeerRecipe::Formula.new.tinseth(@recipe.batch_size, @record.time, @recipe.og, @record.alpha, amount)
    ibu = adjust_bitterness(ibu)
    ibu
  else
    0
  end
end

#contributes_bitterness?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/beer_recipe/hop_wrapper.rb', line 48

def contributes_bitterness?
  !dryhop?
end

#dryhop?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/beer_recipe/hop_wrapper.rb', line 56

def dryhop?
  @record.use == 'Dry Hop' || @record.time > 320
end

#formatted_amountObject



84
85
86
# File 'lib/beer_recipe/hop_wrapper.rb', line 84

def formatted_amount
 "#{'%.0f' % amount}"
end

#formatted_ibuObject



88
89
90
# File 'lib/beer_recipe/hop_wrapper.rb', line 88

def formatted_ibu
 "#{'%.1f' % ibu}"
end

#formatted_timeObject



68
69
70
71
72
73
74
# File 'lib/beer_recipe/hop_wrapper.rb', line 68

def formatted_time
  if dryhop?
    "#{'%.0f' % (@record.time / 1440)}"
  else
    "#{'%.0f' % @record.time}"
  end
end

#has_needed_ibu_values?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/beer_recipe/hop_wrapper.rb', line 52

def has_needed_ibu_values?
  @recipe.has_final_values? && @recipe.batch_size > 0 && amount > 0 && @record.time > 0
end

#ibuObject



16
17
18
# File 'lib/beer_recipe/hop_wrapper.rb', line 16

def ibu
  @ibu ||= calculate_ibu
end

#mgl_added_alpha_acidsObject

mg/l of added alpha acids



12
13
14
# File 'lib/beer_recipe/hop_wrapper.rb', line 12

def mgl_added_alpha_acids
  BeerRecipe::Formula.new.mgl_added_alpha_acids(@recipe.batch_size, @record.alpha, amount)
end

#time_unitObject



76
77
78
79
80
81
82
# File 'lib/beer_recipe/hop_wrapper.rb', line 76

def time_unit
  if dryhop?
    'days'
  else
    'min'
  end
end