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
- #dst_adjust? ⇒ Boolean
-
#initialize(interval, week_start) ⇒ Validation
constructor
A new instance of Validation.
- #type ⇒ Object
- #validate(step_time, start_time) ⇒ Object
Constructor Details
#initialize(interval, week_start) ⇒ Validation
Returns a new instance of Validation.
19 20 21 22 |
# File 'lib/ice_cube/validations/weekly_interval.rb', line 19 def initialize(interval, week_start) @interval = interval @week_start = week_start end |
Instance Attribute Details
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
17 18 19 |
# File 'lib/ice_cube/validations/weekly_interval.rb', line 17 def interval @interval end |
#week_start ⇒ Object (readonly)
Returns the value of attribute week_start.
17 18 19 |
# File 'lib/ice_cube/validations/weekly_interval.rb', line 17 def week_start @week_start end |
Instance Method Details
#build_hash(builder) ⇒ Object
47 48 49 50 |
# File 'lib/ice_cube/validations/weekly_interval.rb', line 47 def build_hash(builder) builder[:interval] = interval builder[:week_start] = TimeUtil.sym_to_wday(week_start) end |
#build_ical(builder) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/ice_cube/validations/weekly_interval.rb', line 52 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
43 44 45 |
# File 'lib/ice_cube/validations/weekly_interval.rb', line 43 def build_s(builder) builder.base = IceCube::I18n.t('ice_cube.each_week', count: interval) end |
#dst_adjust? ⇒ Boolean
28 29 30 |
# File 'lib/ice_cube/validations/weekly_interval.rb', line 28 def dst_adjust? true end |
#type ⇒ Object
24 25 26 |
# File 'lib/ice_cube/validations/weekly_interval.rb', line 24 def type :day end |
#validate(step_time, start_time) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ice_cube/validations/weekly_interval.rb', line 32 def validate(step_time, start_time) return if step_time < start_time t0, t1 = 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.to_i / 7) % interval).nonzero? (interval - offset) * 7 if offset end |