Module: Toji::Product

Defined in:
lib/toji/product.rb,
lib/toji/product/schedule_factory.rb

Defined Under Namespace

Modules: ScheduleFactory

Instance Method Summary collapse

Instance Method Details

#compactObject



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

def compact
  Utils.check_dup(self)

  dst = self.dup
  dst.compact!
end

#compact!Object



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