Class: IceCube::Validations::DailyInterval::Validation

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(interval) ⇒ Validation

Returns a new instance of Validation.



18
19
20
# File 'lib/ice_cube/validations/daily_interval.rb', line 18

def initialize(interval)
  @interval = interval
end

Instance Attribute Details

#intervalObject (readonly)

Returns the value of attribute interval.



16
17
18
# File 'lib/ice_cube/validations/daily_interval.rb', line 16

def interval
  @interval
end

Instance Method Details

#build_hash(builder) ⇒ Object



42
43
44
# File 'lib/ice_cube/validations/daily_interval.rb', line 42

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

#build_ical(builder) ⇒ Object



46
47
48
49
# File 'lib/ice_cube/validations/daily_interval.rb', line 46

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

#build_s(builder) ⇒ Object



38
39
40
# File 'lib/ice_cube/validations/daily_interval.rb', line 38

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

#dst_adjust?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/ice_cube/validations/daily_interval.rb', line 26

def dst_adjust?
  true
end

#typeObject



22
23
24
# File 'lib/ice_cube/validations/daily_interval.rb', line 22

def type
  :day
end

#validate(step_time, start_time) ⇒ Object



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

def validate(step_time, start_time)
  t0, t1 = start_time, step_time
  days = Date.new(t1.year, t1.month, t1.day) -
    Date.new(t0.year, t0.month, t0.day)
  offset = (days % interval).nonzero?
  interval - offset if offset
end