Module: Toji::Recipe::Step

Defined in:
lib/toji/recipe/step.rb

Instance Method Summary collapse

Instance Method Details

#*(other) ⇒ Object



193
194
195
196
197
198
199
200
# File 'lib/toji/recipe/step.rb', line 193

def *(other)
  if Integer===other || Float===other
    scale(other)
  else
    x, y = other.coerce(self)
    x * y
  end
end

#+(other) ⇒ Object



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/toji/recipe/step.rb', line 171

def +(other)
  if Step===other
    Utils.check_dup(self)
    Utils.check_dup(other)

    dst = self.dup
    other = other.dup

    dst.kojis = Utils.merge_ingredients(dst.kojis, other.kojis)
    dst.kakes = Utils.merge_ingredients(dst.kakes, other.kakes)
    dst.waters = Utils.merge_ingredients(dst.waters, other.waters)
    dst.lactic_acids = Utils.merge_ingredients(dst.lactic_acids, other.lactic_acids)
    dst.alcohols = Utils.merge_ingredients(dst.alcohols, other.alcohols)
    dst.yeasts = Utils.merge_ingredients(dst.yeasts, other.yeasts)

    dst
  else
    x, y = other.coerce(self)
    x + y
  end
end

#alcohol_totalObject

醸造アルコール



52
53
54
# File 'lib/toji/recipe/step.rb', line 52

def alcohol_total
  (alcohols || []).map(&:weight).map(&:to_f).sum.to_f
end

#compactObject



164
165
166
167
168
169
# File 'lib/toji/recipe/step.rb', line 164

def compact
  Utils.check_dup(self)

  dst = self.dup
  dst.compact!
end

#compact!Object



150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/toji/recipe/step.rb', line 150

def compact!
  kojis.select! {|koji| 0<koji.weight.to_f}
  kojis.each {|koji|
    koji.tanekojis.select! {|tanekoji| 0<tanekoji.ratio.to_f}
  }
  kakes.select! {|kake| 0<kake.weight.to_f}
  waters.select! {|water| 0<water.weight.to_f}
  lactic_acids.select! {|lactic_acid| 0<lactic_acid.weight.to_f}
  alcohols.select! {|alcohol| 0<alcohol.weight.to_f}
  yeasts.select! {|yeast| 0<yeast.weight.to_f}

  self
end

#ingredients(&block) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/toji/recipe/step.rb', line 79

def ingredients(&block)
  Enumerator.new do|y|
    kojis&.each {|koji|
      y << koji
    }
    kakes&.each {|kake|
      y << kake
    }
    waters&.each {|water|
      y << water
    }
    lactic_acids&.each {|lactic_acid|
      y << lactic_acid
    }
    alcohols&.each {|alcohol|
      y << alcohol
    }
    yeasts&.each {|yeast|
      y << yeast
    }
  end.each(&block)
end

#kake_totalObject

掛米



32
33
34
# File 'lib/toji/recipe/step.rb', line 32

def kake_total
  (kakes || []).map(&:weight).map(&:to_f).sum.to_f
end

#koji_ratioObject

麹歩合



57
58
59
60
# File 'lib/toji/recipe/step.rb', line 57

def koji_ratio
  val = koji_total / rice_total
  val.nan? ? 0.0 : val
end

#koji_totalObject

麹米



27
28
29
# File 'lib/toji/recipe/step.rb', line 27

def koji_total
  (kojis || []).map(&:weight).map(&:to_f).sum.to_f
end

#lactic_acid_totalObject

乳酸



47
48
49
# File 'lib/toji/recipe/step.rb', line 47

def lactic_acid_total
  (lactic_acids || []).map(&:weight).map(&:to_f).sum.to_f
end

#moto?Boolean

Returns:

  • (Boolean)


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

def moto?
  index==0
end

#rice_totalObject

総米



37
38
39
# File 'lib/toji/recipe/step.rb', line 37

def rice_total
  koji_total + kake_total
end

#rices(&block) ⇒ Object



68
69
70
71
72
73
74
75
76
77
# File 'lib/toji/recipe/step.rb', line 68

def rices(&block)
  Enumerator.new do|y|
    kojis&.each {|koji|
      y << koji
    }
    kakes&.each {|kake|
      y << kake
    }
  end.each(&block)
end

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



143
144
145
146
147
148
# File 'lib/toji/recipe/step.rb', line 143

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



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/toji/recipe/step.rb', line 116

def round!(ndigit=0, mini_ndigit=nil, half: :up)
  if !mini_ndigit
    mini_ndigit = ndigit + 3
  end

  kojis&.each {|koji|
    koji.weight = koji.weight.to_f.round(ndigit, half: half)
  }
  kakes&.each {|kake|
    kake.weight = kake.weight.to_f.round(ndigit, half: half)
  }
  waters&.each {|water|
    water.weight = water.weight.to_f.round(ndigit, half: half)
  }
  lactic_acids&.each {|lactic_acid|
    lactic_acid.weight = lactic_acid.weight.to_f.round(mini_ndigit, half: half)
  }
  alcohols&.each {|alcohol|
    alcohol.weight = alcohol.weight.to_f.round(ndigit, half: half)
  }
  yeasts&.each {|yeast|
    yeast.weight = yeast.weight.to_f.round(mini_ndigit, half: half)
  }

  self
end

#scale(ratio) ⇒ Object



109
110
111
112
113
114
# File 'lib/toji/recipe/step.rb', line 109

def scale(ratio)
  Utils.check_dup(self)

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

#scale!(ratio) ⇒ Object



102
103
104
105
106
107
# File 'lib/toji/recipe/step.rb', line 102

def scale!(ratio)
  ingredients.each {|ingredient|
    ingredient.weight *= ratio
  }
  self
end

#water_ratioObject

汲水歩合



63
64
65
66
# File 'lib/toji/recipe/step.rb', line 63

def water_ratio
  val = water_total / rice_total
  val.nan? ? 0.0 : val
end

#water_totalObject

汲水



42
43
44
# File 'lib/toji/recipe/step.rb', line 42

def water_total
  (waters || []).map(&:weight).map(&:to_f).sum.to_f
end