Class: Brewscribe::Grain

Inherits:
Object
  • Object
show all
Includes:
Conversion
Defined in:
lib/brewscribe/grain.rb

Constant Summary collapse

TYPES =
['Grain', 'Extract Sugar', 'Adjunct', 'Dry Extract']
KEY_CONVERSION =
{
  amount: FLOAT_CONV,
  color: FLOAT_CONV,
  yield: ->(k) { k.to_f * 0.01 },
  price: FLOAT_CONV,
  boil_time: ->(k) { k.to_i },
  percent: PERCENT_CONV,
  max_in_batch: PERCENT_CONV,
  add_after_boil: BOOLEAN_CONV,
  recommend_mash: BOOLEAN_CONV,
  in_recipe: BOOLEAN_CONV,
  type: ->(k) { TYPES[k.to_i] },
  ibu_gal_per_lb: FLOAT_CONV,
  protein: PERCENT_CONV,
  diastatic_power: PERCENT_CONV,
  late_extract: FLOAT_CONV,
  moisture: PERCENT_CONV,
  coarse_fine_diff: PERCENT_CONV
}

Constants included from Conversion

Conversion::BOOLEAN_CONV, Conversion::DATE_CONV, Conversion::FLOAT_CONV, Conversion::INT_CONV, Conversion::PERCENT_CONV

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Conversion

#data_to_properties

Constructor Details

#initialize(grain_data) ⇒ Grain

Returns a new instance of Grain.



34
35
36
37
38
# File 'lib/brewscribe/grain.rb', line 34

def initialize grain_data
  @original_data = grain_data 

  data_to_properties grain_data
end

Instance Attribute Details

#add_after_boilObject (readonly)

Returns the value of attribute add_after_boil.



5
6
7
# File 'lib/brewscribe/grain.rb', line 5

def add_after_boil
  @add_after_boil
end

#amountObject (readonly)

Returns the value of attribute amount.



5
6
7
# File 'lib/brewscribe/grain.rb', line 5

def amount
  @amount
end

#boil_timeObject (readonly)

Returns the value of attribute boil_time.



5
6
7
# File 'lib/brewscribe/grain.rb', line 5

def boil_time
  @boil_time
end

#coarse_fine_diffObject (readonly)

Returns the value of attribute coarse_fine_diff.



5
6
7
# File 'lib/brewscribe/grain.rb', line 5

def coarse_fine_diff
  @coarse_fine_diff
end

#colorObject (readonly)

Returns the value of attribute color.



5
6
7
# File 'lib/brewscribe/grain.rb', line 5

def color
  @color
end

#convert_grainObject (readonly)

Returns the value of attribute convert_grain.



5
6
7
# File 'lib/brewscribe/grain.rb', line 5

def convert_grain
  @convert_grain
end

#diastatic_powerObject (readonly)

Returns the value of attribute diastatic_power.



5
6
7
# File 'lib/brewscribe/grain.rb', line 5

def diastatic_power
  @diastatic_power
end

#ibu_gal_per_lbObject (readonly)

Returns the value of attribute ibu_gal_per_lb.



5
6
7
# File 'lib/brewscribe/grain.rb', line 5

def ibu_gal_per_lb
  @ibu_gal_per_lb
end

#in_recipeObject (readonly)

Returns the value of attribute in_recipe.



5
6
7
# File 'lib/brewscribe/grain.rb', line 5

def in_recipe
  @in_recipe
end

#late_extractObject (readonly)

Returns the value of attribute late_extract.



5
6
7
# File 'lib/brewscribe/grain.rb', line 5

def late_extract
  @late_extract
end

#max_in_batchObject (readonly)

Returns the value of attribute max_in_batch.



5
6
7
# File 'lib/brewscribe/grain.rb', line 5

def max_in_batch
  @max_in_batch
end

#moistureObject (readonly)

Returns the value of attribute moisture.



5
6
7
# File 'lib/brewscribe/grain.rb', line 5

def moisture
  @moisture
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/brewscribe/grain.rb', line 5

def name
  @name
end

#notesObject (readonly)

Returns the value of attribute notes.



5
6
7
# File 'lib/brewscribe/grain.rb', line 5

def notes
  @notes
end

#originObject (readonly)

Returns the value of attribute origin.



5
6
7
# File 'lib/brewscribe/grain.rb', line 5

def origin
  @origin
end

#percentObject (readonly)

Returns the value of attribute percent.



5
6
7
# File 'lib/brewscribe/grain.rb', line 5

def percent
  @percent
end

#priceObject (readonly)

Returns the value of attribute price.



5
6
7
# File 'lib/brewscribe/grain.rb', line 5

def price
  @price
end

#proteinObject (readonly)

Returns the value of attribute protein.



5
6
7
# File 'lib/brewscribe/grain.rb', line 5

def protein
  @protein
end

#recommend_mashObject (readonly)

Returns the value of attribute recommend_mash.



5
6
7
# File 'lib/brewscribe/grain.rb', line 5

def recommend_mash
  @recommend_mash
end

#supplierObject (readonly)

Returns the value of attribute supplier.



5
6
7
# File 'lib/brewscribe/grain.rb', line 5

def supplier
  @supplier
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/brewscribe/grain.rb', line 5

def type
  @type
end

#yieldObject (readonly)

Returns the value of attribute yield.



5
6
7
# File 'lib/brewscribe/grain.rb', line 5

def yield
  @yield
end

Instance Method Details

#in_poundsObject



48
49
50
# File 'lib/brewscribe/grain.rb', line 48

def in_pounds
  self.amount / 16.0
end

#ppgObject



40
41
42
# File 'lib/brewscribe/grain.rb', line 40

def ppg
  self.yield * 46.214
end

#total_ppgObject



44
45
46
# File 'lib/brewscribe/grain.rb', line 44

def total_ppg
  ppg * in_pounds
end