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



65
66
67
68
69
70
# File 'lib/toji/recipe.rb', line 65

def compact
  Utils.check_dup(self)

  dst = self.dup
  dst.compact!
end

#compact!Object



55
56
57
58
59
60
61
62
63
# File 'lib/toji/recipe.rb', line 55

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

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

  self
end

#cumulate(key) ⇒ Object

累計



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

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

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

#cumulative_koji_ratiosObject

麹歩合の累計



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

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

総米の累計



156
157
158
# File 'lib/toji/recipe.rb', line 156

def cumulative_rice_totals
  cumulate(:rice_total)
end

#cumulative_water_ratiosObject

汲水歩合の累計



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

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

掛米精米歩合



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

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

麹米精米歩合



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

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



93
94
95
96
# File 'lib/toji/recipe.rb', line 93

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

#max_interval_daysObject



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

def max_interval_days
  [
    steps&.map(&:interval_days)&.max,
    steps&.flat_map{|step| step.rices.to_a}&.map(&:interval_days)&.max,
    actions&.map(&:interval_days)&.max,
  ].compact.max
end

#moto_ratioObject

酒母歩合

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

出典: 酒造教本 P96



118
119
120
# File 'lib/toji/recipe.rb', line 118

def moto_ratio
  moto_ratios.last || 0.0
end

#moto_ratiosObject

酒母歩合の累計



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

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

白米比率

発酵型と白米比率

発酵の型    酒母  添  仲  留  特徴
湧き進め型     1   2   4   6  短期醪、辛口、軽快な酒質
湧き抑え型     1   2   4   7  長期醪、甘口、おだやかな酒質

出典: 酒造教本 P95



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

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

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

#rice_totalObject

総米



84
85
86
# File 'lib/toji/recipe.rb', line 84

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

#rice_total_percentagesObject

総米の割合



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

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



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

def table
  data = table_data

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

#table_dataObject



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
257
258
# File 'lib/toji/recipe.rb', line 220

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



107
108
109
110
# File 'lib/toji/recipe.rb', line 107

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