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.


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

def initialize(interval)
  @interval = interval
end

Instance Attribute Details

#intervalObject (readonly)

Returns the value of attribute interval


17
18
19
# File 'lib/ice_cube/validations/monthly_interval.rb', line 17

def interval
  @interval
end

Instance Method Details

#build_hash(builder) ⇒ Object


43
44
45
# File 'lib/ice_cube/validations/monthly_interval.rb', line 43

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

#build_ical(builder) ⇒ Object


47
48
49
50
# File 'lib/ice_cube/validations/monthly_interval.rb', line 47

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

#build_s(builder) ⇒ Object


39
40
41
# File 'lib/ice_cube/validations/monthly_interval.rb', line 39

def build_s(builder)
  builder.base = IceCube::I18n.t('ice_cube.each_month', count: interval)
end

#dst_adjust?Boolean

Returns:

  • (Boolean)

27
28
29
# File 'lib/ice_cube/validations/monthly_interval.rb', line 27

def dst_adjust?
  true
end

#typeObject


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

def type
  :month
end

#validate(step_time, start_time) ⇒ Object


31
32
33
34
35
36
37
# File 'lib/ice_cube/validations/monthly_interval.rb', line 31

def validate(step_time, start_time)
  t0, t1 = start_time, step_time
  months = (t1.month - t0.month) +
           (t1.year - t0.year) * 12
  offset = (months % interval).nonzero?
  interval - offset if offset
end