Class: ForemanPatch::CycleNameGenerator

Inherits:
Object
  • Object
show all
Defined in:
app/services/foreman_patch/cycle_name_generator.rb

Constant Summary collapse

REGEX =
/%([-_0^#:]*)(\d*)([q])/.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(format, date) ⇒ CycleNameGenerator

Returns a new instance of CycleNameGenerator.



22
23
24
25
# File 'app/services/foreman_patch/cycle_name_generator.rb', line 22

def initialize(format, date)
  @format = format
  @date = date
end

Instance Attribute Details

#dateObject

Returns the value of attribute date.



20
21
22
# File 'app/services/foreman_patch/cycle_name_generator.rb', line 20

def date
  @date
end

#formatObject

Returns the value of attribute format.



20
21
22
# File 'app/services/foreman_patch/cycle_name_generator.rb', line 20

def format
  @format
end

Class Method Details

.generate(plan) ⇒ Object



5
6
7
8
9
10
# File 'app/services/foreman_patch/cycle_name_generator.rb', line 5

def self.generate(plan)
  return plan.name if plan.cycle_name.blank?

  generator = new(plan.cycle_name, plan.start_date)
  generator.render
end

.rename(cycle) ⇒ Object



12
13
14
15
16
17
18
# File 'app/services/foreman_patch/cycle_name_generator.rb', line 12

def self.rename(cycle)
  return if cycle.plan.blank?
  return if cycle.plan.cycle_name.blank?

  generator = new(cycle.plan.cycle_name, cycle.start_date)
  cycle.update(name: generator.render)
end

Instance Method Details

#renderObject



27
28
29
# File 'app/services/foreman_patch/cycle_name_generator.rb', line 27

def render
  date.strftime(format.gsub(REGEX, quarter(date)))
end