Class: IceCube::Validations::YearlyInterval::Validation

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(interval) ⇒ Validation

Returns a new instance of Validation.



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

def initialize(interval)
  @interval = interval
end

Instance Attribute Details

#intervalObject (readonly)

Returns the value of attribute interval.



11
12
13
# File 'lib/ice_cube/validations/yearly_interval.rb', line 11

def interval
  @interval
end

Instance Method Details

#build_hash(builder) ⇒ Object



35
36
37
# File 'lib/ice_cube/validations/yearly_interval.rb', line 35

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

#build_ical(builder) ⇒ Object



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

def build_ical(builder)
  builder["FREQ"] << "YEARLY"
  unless interval == 1
    builder["INTERVAL"] << interval
  end
end

#build_s(builder) ⇒ Object



31
32
33
# File 'lib/ice_cube/validations/yearly_interval.rb', line 31

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

#dst_adjust?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/ice_cube/validations/yearly_interval.rb', line 21

def dst_adjust?
  true
end

#typeObject



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

def type
  :year
end

#validate(step_time, start_time) ⇒ Object



25
26
27
28
29
# File 'lib/ice_cube/validations/yearly_interval.rb', line 25

def validate(step_time, start_time)
  years = step_time.year - start_time.year
  offset = (years % interval).nonzero?
  interval - offset if offset
end