Class: IceCube::Validations::DailyInterval::Validation
- Inherits:
-
Object
- Object
- IceCube::Validations::DailyInterval::Validation
- Defined in:
- lib/ice_cube/validations/daily_interval.rb
Instance Attribute Summary collapse
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
Instance Method Summary collapse
- #build_hash(builder) ⇒ Object
- #build_ical(builder) ⇒ Object
- #build_s(builder) ⇒ Object
- #dst_adjust? ⇒ Boolean
-
#initialize(interval) ⇒ Validation
constructor
A new instance of Validation.
- #type ⇒ Object
- #validate(step_time, start_time) ⇒ Object
Constructor Details
#initialize(interval) ⇒ Validation
Returns a new instance of Validation.
21 22 23 |
# File 'lib/ice_cube/validations/daily_interval.rb', line 21 def initialize(interval) @interval = interval end |
Instance Attribute Details
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
19 20 21 |
# File 'lib/ice_cube/validations/daily_interval.rb', line 19 def interval @interval end |
Instance Method Details
#build_hash(builder) ⇒ Object
45 46 47 |
# File 'lib/ice_cube/validations/daily_interval.rb', line 45 def build_hash(builder) builder[:interval] = interval end |
#build_ical(builder) ⇒ Object
49 50 51 52 |
# File 'lib/ice_cube/validations/daily_interval.rb', line 49 def build_ical(builder) builder['FREQ'] << 'DAILY' builder['INTERVAL'] << interval unless interval == 1 end |
#build_s(builder) ⇒ Object
41 42 43 |
# File 'lib/ice_cube/validations/daily_interval.rb', line 41 def build_s(builder) builder.base = IceCube::I18n.t('ice_cube.each_day', count: interval) end |
#dst_adjust? ⇒ Boolean
29 30 31 |
# File 'lib/ice_cube/validations/daily_interval.rb', line 29 def dst_adjust? true end |
#type ⇒ Object
25 26 27 |
# File 'lib/ice_cube/validations/daily_interval.rb', line 25 def type :day end |
#validate(step_time, start_time) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/ice_cube/validations/daily_interval.rb', line 33 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 |