Class: IceCube::Validations::MonthlyInterval::Validation

Inherits:
Object
  • Object
show all
Defined in:
lib/ice_cube/validations/monthly_interval.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(interval) ⇒ Validation

Returns a new instance of Validation.



34
35
36
# File 'lib/ice_cube/validations/monthly_interval.rb', line 34

def initialize(interval)
  @interval = interval
end

Instance Attribute Details

#intervalObject (readonly)

Returns the value of attribute interval.



13
14
15
# File 'lib/ice_cube/validations/monthly_interval.rb', line 13

def interval
  @interval
end

Instance Method Details

#build_hash(builder) ⇒ Object



30
31
32
# File 'lib/ice_cube/validations/monthly_interval.rb', line 30

def build_hash(builder)
  builder[:interval] = interval
end

#build_ical(builder) ⇒ Object



23
24
25
26
27
28
# File 'lib/ice_cube/validations/monthly_interval.rb', line 23

def build_ical(builder)
  builder['FREQ'] << 'MONTHLY'
  unless interval == 1
    builder['INTERVAL'] << interval
  end
end

#build_s(builder) ⇒ Object



19
20
21
# File 'lib/ice_cube/validations/monthly_interval.rb', line 19

def build_s(builder)
  builder.base = interval == 1 ? 'Monthly' : "Every #{interval} months"
end

#typeObject



15
16
17
# File 'lib/ice_cube/validations/monthly_interval.rb', line 15

def type
  :month
end

#validate(time, schedule) ⇒ Object

Raises:



38
39
40
41
42
43
44
45
# File 'lib/ice_cube/validations/monthly_interval.rb', line 38

def validate(time, schedule)
  raise ZeroInterval if interval == 0
  start_time = schedule.start_time
  months_to_start = (time.month - start_time.month) + (time.year - start_time.year) * 12
  unless months_to_start % interval == 0
    interval - (months_to_start % interval)
  end
end