16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/toji/product.rb', line 16
def compact!
recipe&.compact!
min_interval_days = [
recipe&.steps&.map(&:interval_days)&.min,
recipe&.steps&.flat_map{|step| step.rices.to_a}&.map(&:interval_days)&.min,
recipe&.actions&.map(&:interval_days)&.min,
].compact.min
if min_interval_days && min_interval_days!=0
recipe&.steps&.each {|step|
step.interval_days -= min_interval_days
step.rices {|rice|
rice.interval_days -= min_interval_days
}
}
recipe&.actions&.each {|action|
action.interval_days -= min_interval_days
}
self.base_date = base_date.since(min_interval_days.days)
end
self
end
|