Class: IceCube::Validations::SecondlyInterval::Validation

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(interval) ⇒ Validation

Returns a new instance of Validation.



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

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/secondly_interval.rb', line 13

def interval
  @interval
end

Instance Method Details

#build_hash(builder) ⇒ Object



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

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

#build_ical(builder) ⇒ Object



27
28
29
30
31
32
# File 'lib/ice_cube/validations/secondly_interval.rb', line 27

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

#build_s(builder) ⇒ Object



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

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

#dst_adjust?Boolean

Returns:

  • (Boolean)


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

def dst_adjust?
  false
end

#typeObject



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

def type
  :sec
end

#validate(time, schedule) ⇒ Object

Raises:



42
43
44
45
46
47
48
# File 'lib/ice_cube/validations/secondly_interval.rb', line 42

def validate(time, schedule)
  raise ZeroInterval if interval == 0
  seconds = time.to_i - schedule.start_time.to_i
  unless seconds % interval == 0
    interval - (seconds % interval)
  end
end