Class: IceCube::Validations::WeeklyInterval::Validation
- Inherits:
-
Object
- Object
- IceCube::Validations::WeeklyInterval::Validation
- Defined in:
- lib/ice_cube/validations/weekly_interval.rb
Instance Attribute Summary collapse
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
-
#week_start ⇒ Object
readonly
Returns the value of attribute week_start.
Instance Method Summary collapse
- #build_hash(builder) ⇒ Object
- #build_ical(builder) ⇒ Object
- #build_s(builder) ⇒ Object
-
#initialize(interval, week_start) ⇒ Validation
constructor
A new instance of Validation.
- #type ⇒ Object
- #validate(step_time, schedule) ⇒ Object
Constructor Details
#initialize(interval, week_start) ⇒ Validation
Returns a new instance of Validation.
23 24 25 26 |
# File 'lib/ice_cube/validations/weekly_interval.rb', line 23 def initialize(interval, week_start) @interval = interval @week_start = week_start end |
Instance Attribute Details
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
21 22 23 |
# File 'lib/ice_cube/validations/weekly_interval.rb', line 21 def interval @interval end |
#week_start ⇒ Object (readonly)
Returns the value of attribute week_start.
21 22 23 |
# File 'lib/ice_cube/validations/weekly_interval.rb', line 21 def week_start @week_start end |
Instance Method Details
#build_hash(builder) ⇒ Object
46 47 48 49 |
# File 'lib/ice_cube/validations/weekly_interval.rb', line 46 def build_hash(builder) builder[:interval] = interval builder[:week_start] = TimeUtil.sym_to_wday(week_start) end |
#build_ical(builder) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/ice_cube/validations/weekly_interval.rb', line 51 def build_ical(builder) builder['FREQ'] << 'WEEKLY' unless interval == 1 builder['INTERVAL'] << interval builder['WKST'] << week_start.to_s.upcase[0..1] end end |
#build_s(builder) ⇒ Object
42 43 44 |
# File 'lib/ice_cube/validations/weekly_interval.rb', line 42 def build_s(builder) builder.base = interval == 1 ? 'Weekly' : "Every #{interval} weeks" end |
#type ⇒ Object
28 29 30 |
# File 'lib/ice_cube/validations/weekly_interval.rb', line 28 def type :day end |
#validate(step_time, schedule) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/ice_cube/validations/weekly_interval.rb', line 32 def validate(step_time, schedule) t0, t1 = schedule.start_time, step_time d0 = Date.new(t0.year, t0.month, t0.day) d1 = Date.new(t1.year, t1.month, t1.day) days = (d1 - TimeUtil.normalize_wday(d1.wday, week_start)) - (d0 - TimeUtil.normalize_wday(d0.wday, week_start)) offset = ((days / 7) % interval).nonzero? (interval - offset) * 7 if offset end |