Module: Toji::Recipe

Defined in:
lib/toji/recipe.rb,
lib/toji/recipe/step.rb,
lib/toji/recipe/action.rb,
lib/toji/recipe/ab_expect.rb

Defined Under Namespace

Modules: AbExpect, Action, Step

Instance Method Summary collapse

Instance Method Details

#compactObject



71
72
73
74
75
76
# File 'lib/toji/recipe.rb', line 71

def compact
  Utils.check_dup(self)

  dst = self.dup
  dst.compact!
end

#compact!Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/toji/recipe.rb', line 55

def compact!
  steps.map(&:compact!)
  steps.select! {|step| 0<step.ingredients.to_a.length}

  indexes = steps.map{|step| {index: step.index, subindex: step.subindex}}
  duplicates = indexes - indexes.uniq
  if 0<duplicates.length
    raise DuplicateStepIndexError.new(duplicates)
  end

  ab_expects.select! {|ab| ab.alcohol && ab.nihonshudo}
  ab_expects.uniq! {|ab| [ab.alcohol, ab.nihonshudo]}

  self
end

#cumulate(key) ⇒ Object

累計



145
146
147
148
149
150
151
# File 'lib/toji/recipe.rb', line 145

def cumulate(key)
  values = steps.map(&key)

  values.map.with_index {|x,i|
    values[0..i].sum
  }
end

#cumulative_koji_ratiosObject

麹歩合の累計



159
160
161
162
163
164
165
166
# File 'lib/toji/recipe.rb', line 159

def cumulative_koji_ratios
  rice_totals = cumulate(:rice_total)
  koji_totals = cumulate(:koji_total)

  rice_totals.map.with_index {|rice_total,i|
    koji_totals[i] / rice_total
  }
end

#cumulative_rice_totalsObject

総米の累計



154
155
156
# File 'lib/toji/recipe.rb', line 154

def cumulative_rice_totals
  cumulate(:rice_total)
end

#cumulative_water_ratiosObject

汲水歩合の累計



169
170
171
172
173
174
175
176
# File 'lib/toji/recipe.rb', line 169

def cumulative_water_ratios
  rice_totals = cumulate(:rice_total)
  water_totals = cumulate(:water_total)

  rice_totals.map.with_index {|rice_total,i|
    water_totals[i] / rice_total
  }
end

#ingredients(&block) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/toji/recipe.rb', line 12

def ingredients(&block)
  Enumerator.new do|y|
    steps&.each {|step|
      step.ingredients.each {|ingredient|
        y << [step, ingredient]
      }
    }
  end.each(&block)
end

#kake_polishing_ratioObject

掛米精米歩合



132
133
134
135
136
137
138
139
140
# File 'lib/toji/recipe.rb', line 132

def kake_polishing_ratio
  kakes = steps.flat_map{|step| step.kakes}.select{|kake| 0<kake.weight}
  if kakes.length==0 || kakes.find{|kake| !kake.polishing_ratio}
    Float::NAN
  else
    ratio_sum = kakes.map{|kake| kake.polishing_ratio * kake.weight}.sum.to_f
    ratio_sum / steps.map(&:kake_total).sum.to_f
  end
end

#koji_polishing_ratioObject

麹米精米歩合



121
122
123
124
125
126
127
128
129
# File 'lib/toji/recipe.rb', line 121

def koji_polishing_ratio
  kojis = steps.flat_map{|step| step.kojis}.select{|koji| 0<koji.weight}
  if kojis.length==0 || kojis.find{|koji| !koji.polishing_ratio}
    Float::NAN
  else
    ratio_sum = kojis.map{|koji| koji.polishing_ratio * koji.weight}.sum.to_f
    ratio_sum / steps.map(&:koji_total).sum.to_f
  end
end

#koji_ratioObject

麹歩合原料白米に占める麹米の割合留め仕込みまでの総米重量の20〜22%が標準であるなお、留め仕込みまでの麹歩合が20%を下回ると蒸米の溶解糖化に影響が出るので注意がいる出典: 酒造教本 P95



91
92
93
94
# File 'lib/toji/recipe.rb', line 91

def koji_ratio
  val = steps.map(&:koji_total).sum.to_f / rice_total
  val.nan? ? 0.0 : val
end

#moto_ratioObject

酒母歩合

7%が標準である汲水歩合が大きい高温糖化酒母では6%程度である

出典: 酒造教本 P96



116
117
118
# File 'lib/toji/recipe.rb', line 116

def moto_ratio
  moto_ratios.last || 0.0
end

#moto_ratiosObject

酒母歩合の累計



208
209
210
211
212
213
214
215
# File 'lib/toji/recipe.rb', line 208

def moto_ratios
  rice_total = steps.map(&:rice_total)
  moto = steps.select(&:moto?).map(&:rice_total).sum.to_f

  rice_total.map.with_index {|x,i|
    moto / rice_total[0..i].inject(&:+)
  }
end

#rice_ratiosObject

白米比率

発酵型と白米比率

出典: 酒造教本 P95



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

def rice_ratios
  moto = steps.select(&:moto?).map(&:rice_total).sum.to_f

  steps.map {|step|
    step.rice_total / moto
  }
end

#rice_totalObject

総米



82
83
84
# File 'lib/toji/recipe.rb', line 82

def rice_total
  steps.map(&:rice_total).sum.to_f
end

#rice_total_percentagesObject

総米の割合



198
199
200
201
202
203
204
205
# File 'lib/toji/recipe.rb', line 198

def rice_total_percentages
  rice_totals = steps.map(&:rice_total)
  total = rice_totals.sum

  rice_totals.map {|rice_total|
    rice_total / total
  }
end

#round(ndigit = 0, mini_ndigit = nil, half: :up) ⇒ Object



48
49
50
51
52
53
# File 'lib/toji/recipe.rb', line 48

def round(ndigit=0, mini_ndigit=nil, half: :up)
  Utils.check_dup(self)

  dst = self.dup
  dst.round!(ndigit, mini_ndigit, half: half)
end

#round!(ndigit = 0, mini_ndigit = nil, half: :up) ⇒ Object



41
42
43
44
45
46
# File 'lib/toji/recipe.rb', line 41

def round!(ndigit=0, mini_ndigit=nil, half: :up)
  steps.each {|step|
    step.round!(ndigit, mini_ndigit, half: half)
  }
  self
end

#scale(ratio) ⇒ Object



34
35
36
37
38
39
# File 'lib/toji/recipe.rb', line 34

def scale(ratio)
  Utils.check_dup(self)

  dst = self.dup
  dst.scale!(ratio)
end

#scale!(ratio) ⇒ Object



27
28
29
30
31
32
# File 'lib/toji/recipe.rb', line 27

def scale!(ratio)
  steps.each {|step|
    step.scale!(ratio)
  }
  self
end

#scale_rice_total(rice_total) ⇒ Object



22
23
24
25
# File 'lib/toji/recipe.rb', line 22

def scale_rice_total(rice_total)
  ratio = rice_total.to_f / steps.map(&:rice_total).sum
  scale(ratio)
end

#tableObject



258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/toji/recipe.rb', line 258

def table
  data = table_data

  Plotly::Plot.new(
    data: [{
      type: :table,
      header: {
        values: data[:header]
      },
      cells: {
        values: data[:rows].transpose
      },
    }],
    layout: {
    }
  )
end

#table_dataObject



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/toji/recipe.rb', line 218

def table_data
  headers = [""] + steps.map.with_index{|s,i| :"Step#{i}"} + [:total]
  keys = [["RiceTotal", :rice_total], ["Kake", :kakes], ["Koji", :kojis], ["Alcohol", :alcohols], ["Water", :waters], ["LacticAcid", :lactic_acids]]

  cells = [keys.map(&:first)]
  cells += steps.map {|step|
    keys.map(&:last).map {|key|
      vals = step.send(key)
      if Numeric===vals
        vals
      else
        vals.compact.map(&:weight).sum
      end
    }
  }
  cells << keys.map(&:last).map {|key|
    vals = steps.map(&key)
    if Numeric===vals[0]
      vals.sum
    else
      vals.flatten.compact.map(&:weight).sum
    end
  }

  cells = cells.map {|cell|
    cell.map {|c|
      case c
      when NilClass
        ""
      when 0
        ""
      else
        c
      end
    }
  }

  {header: headers, rows: cells.transpose}
end

#water_ratioObject

汲水歩合

酒母: 110%が標準、高温糖化酒母は150〜180% 添: 85〜100%の範囲で90%が標準、湧き進め型は歩合が高い仲: 120%が標準留: 130〜150%の範囲全体: 留までの総米に対し120〜130%、標準は125%、高級酒は130〜145%である

出典: 酒造教本 P96



105
106
107
108
# File 'lib/toji/recipe.rb', line 105

def water_ratio
  val = steps.map(&:water_total).sum.to_f / rice_total
  val.nan? ? 0.0 : val
end