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.



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

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



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

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

#build_ical(builder) ⇒ Object



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

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

#build_s(builder) ⇒ Object



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

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

#dst_adjust?Boolean

Returns:

  • (Boolean)


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

def dst_adjust?
  false
end

#typeObject



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

def type
  :sec
end

#validate(step_time, start_time) ⇒ Object



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

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