Class: Beercalc

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

Class Method Summary collapse

Class Method Details

.aau(alpha, weight) ⇒ Object

AAU()

param alpha: percent - alpha unit of the hop
param weight: number - oz of hops


53
54
55
56
57
58
59
# File 'lib/beercalc.rb', line 53

def self.aau(alpha, weight)
  unless !alpha.is_a?(Numeric) || !weight.is_a?(Numeric)
    aau = alpha * weight
  else
    aau = nil
  end
end

.abv(og, fg) ⇒ Object

ABV()

param og: number - original gravity
param fg: number - final gravity


6
7
8
9
10
11
12
# File 'lib/beercalc.rb', line 6

def self.abv(og, fg)
  unless og < fg || !og.is_a?(Numeric) || !fg.is_a?(Numeric)
    abv = (og - fg) * 131
  else
    abv = nil
  end
end

.abw(og, fg) ⇒ Object

ABW()

param og: number - original gravity
param fg: number - final gravity
SOURCE = http://hbd.org/ensmingr/


18
19
20
21
22
23
24
# File 'lib/beercalc.rb', line 18

def self.abw(og, fg)
  unless og < fg || !og.is_a?(Numeric) || !fg.is_a?(Numeric)
    abv = (0.79 * self.abv(og, fg)) / fg
  else
    abv = nil
  end
end

.attenuation(og, fg) ⇒ Object

ATTENUATION

param og: number - original gravity
param fg: number - final gracivity
Assuming this is in gravity (Ex. 1.054)


123
124
125
126
127
128
129
# File 'lib/beercalc.rb', line 123

def self.attenuation(og, fg)
  unless og < fg || !og.is_a?(Numeric) || !fg.is_a?(Numeric)
    attenuation = (og - fg)/(og - 1)
  else
    attenuation = nil
  end
end

.calories(og, fg) ⇒ Object

CALORIES (in 12 ounce increments)

param og: number - original gravity
param fg: number - final gravity
SOURCE = http://hbd.org/ensmingr/


111
112
113
114
115
116
117
# File 'lib/beercalc.rb', line 111

def self.calories(og, fg)
  unless og < fg || !og.is_a?(Numeric) || !fg.is_a?(Numeric)
    calories = ((6.9 * self.abw(og,fg)) + 4.0 * (self.realExtract(og,fg) - 0.1)) * fg * 3.55
  else
    calories = nil
  end
end

.extractAddition(target_gu, total_gu, extractType) ⇒ Object

EXTRACT ADDITION param target_gu: number - Target Total Gravity in Gravity Units param total_gu: number - Total Gravity from Mash in Gravity Units param extract: string/number - should be ‘LME’ or ‘DME’ or custom value



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/beercalc.rb', line 168

def self.extractAddition(target_gu, total_gu, extractType)
  # Preset values for LME and DME, or account for a custom value
  if extractType == 'LME'
    extract = 38
  elsif extractType == 'DME'
    extract = 45
  elsif extractType.is_a?(Numeric)
    extract = extractType
  end

  unless !target_gu.is_a?(Numeric) || !total_gu.is_a?(Numeric) || !extract.is_a?(Numeric)
    addition = (target_gu - total_gu).to_f / extract
  else
    addition = nil
  end
  return addition  
end

.finalGravity(g, vol_beg, vol_end) ⇒ Object

FINAL GRAVITY

param g: number - initial gravity
param vol_beg: number - volume in gallons at the begining of the boil
param vol_end: number - volume in gallons at the end of the boil


156
157
158
159
160
161
162
# File 'lib/beercalc.rb', line 156

def self.finalGravity(g, vol_beg, vol_end)
  unless !g.is_a?(Numeric) || !vol_beg.is_a?(Numeric) || !vol_end.is_a?(Numeric)
    gu = self.totalGravity(g,vol_beg) / vol_end
  else
    gu = nil
  end
end

.gravityCorrection(temp, g) ⇒ Object

GRAVITY TEMPERATURE CORRECTION param temp: number - Temperature in Fahrenheit param g: number - Gravity from the hydrometer reading



189
190
191
192
193
194
195
# File 'lib/beercalc.rb', line 189

def self.gravityCorrection(temp, g)
  unless !temp.is_a?(Numeric) || !g.is_a?(Numeric)
    correction = ((1.313454 - 0.132674*temp + 2.057793*10**-3*temp**2 - 2.627634*10**-6*temp**3) * 0.001) + g
  else
    correction = nil
  end
end

.gu(g) ⇒ Object

GRAVITY UNITS

param g: number - gravity


133
134
135
136
137
138
139
# File 'lib/beercalc.rb', line 133

def self.gu(g)
  unless !g.is_a?(Numeric)
    gu = ((g - 1) * 1000).round
  else
    gu = nil
  end 
end

.ibu(alpha, weight, time, gravity, volume) ⇒ Object

IBU()

param alpha: percent - alpha unit of the hop
param weight: number - oz of hops
param utilization: number - output of self.utilization
param volume: number - gallons


66
67
68
69
70
71
72
# File 'lib/beercalc.rb', line 66

def self.ibu(alpha, weight, time, gravity, volume)
  unless volume == 0 || !alpha.is_a?(Numeric) || !weight.is_a?(Numeric) || !time.is_a?(Numeric) || !gravity.is_a?(Numeric) || !volume.is_a?(Numeric)
    ibu = self.aau(alpha, weight) * self.utilization(time, gravity) * 75 / volume
  else
    ibu = nil
  end
end

.mcu(weight, lovibond, volume) ⇒ Object

MCU()

param weight: number - lbs of grain
param lovibond: number - typically a number between 
param volume: number - gallons


30
31
32
33
34
35
36
# File 'lib/beercalc.rb', line 30

def self.mcu(weight, lovibond, volume)
  unless volume == 0 || !weight.is_a?(Numeric) || !lovibond.is_a?(Numeric) || !volume.is_a?(Numeric)
    mcu = (weight * lovibond) / volume
  else
    mcu = nil
  end
end

.plato(sGravity) ⇒ Object

PLATO

param sGravity: number - specific gravity


87
88
89
90
91
92
93
# File 'lib/beercalc.rb', line 87

def self.plato(sGravity)  
  unless !sGravity.is_a?(Numeric) 
    plato = (-463.37) + (668.72 * sGravity) - (205.35 * sGravity**2)
  else
    plato = nil
  end
end

.realExtract(og, fg) ⇒ Object

REAL EXTRACT

param og: number - original gravity
param fg: number - final gracivity
SOURCE = http://hbd.org/ensmingr/


99
100
101
102
103
104
105
# File 'lib/beercalc.rb', line 99

def self.realExtract(og, fg)
  unless !og.is_a?(Numeric) || !fg.is_a?(Numeric) || og < fg
    realExtract = (0.1808 * self.plato(og)) + (0.8192 * self.plato(fg))
  else
    realExtract = nil
  end
end

.srm(weight, lovibond, volume) ⇒ Object

SRM()

param weight: number - lbs of grain
param lovibond: number - typically a number between 1-25
param volume: number - gallons


42
43
44
45
46
47
48
# File 'lib/beercalc.rb', line 42

def self.srm(weight, lovibond, volume)
  unless !weight.is_a?(Numeric) || !lovibond.is_a?(Numeric) || !volume.is_a?(Numeric)
    srm = 1.4922 * (mcu(weight, lovibond, volume) ** 0.6859)
  else
    srm = nil
  end
end

.totalGravity(g, v) ⇒ Object

TOTAL GRAVITY param g: number - gravity param vol: number - volume in gallons



144
145
146
147
148
149
150
# File 'lib/beercalc.rb', line 144

def self.totalGravity(g,v)
  unless !g.is_a?(Numeric) || !v.is_a?(Numeric)
    tg = self.gu(g) * v
  else
    tg = nil
  end
end

.utilization(time, gravity) ⇒ Object

UTILIZATION()

param time: number - minute hops are in the boil
param gravity: number - gravity of the boil upon inserting Ex. 1.050


77
78
79
80
81
82
83
# File 'lib/beercalc.rb', line 77

def self.utilization(time, gravity)
  unless !time.is_a?(Numeric) || !gravity.is_a?(Numeric)
    utilization = (1.65 * 0.000125**(gravity - 1)) * (1 - Math::E**(-0.04 * time)) / 4.15
  else
    utilization = nil
  end
end