Class: IceCube::Validations::HourlyInterval::Validation

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(interval) ⇒ Validation

Returns a new instance of Validation.



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

def initialize(interval)
  @interval = interval
end

Instance Attribute Details

#intervalObject (readonly)

Returns the value of attribute interval.



14
15
16
# File 'lib/ice_cube/validations/hourly_interval.rb', line 14

def interval
  @interval
end

Instance Method Details

#build_hash(builder) ⇒ Object



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

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

#build_ical(builder) ⇒ Object



45
46
47
48
# File 'lib/ice_cube/validations/hourly_interval.rb', line 45

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

#build_s(builder) ⇒ Object



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

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

#dst_adjust?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/ice_cube/validations/hourly_interval.rb', line 24

def dst_adjust?
  false
end

#typeObject



20
21
22
# File 'lib/ice_cube/validations/hourly_interval.rb', line 20

def type
  :hour
end

#validate(step_time, schedule) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/ice_cube/validations/hourly_interval.rb', line 28

def validate(step_time, schedule)
  t0, t1 = schedule.start_time.to_i, step_time.to_i
  sec = (t1 - t1 % ONE_HOUR) -
        (t0 - t0 % ONE_HOUR)
  hours = sec / ONE_HOUR
  offset = (hours % interval).nonzero?
  interval - offset if offset
end