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.
17 18 19 20 |
# File 'lib/ice_cube/validations/weekly_interval.rb', line 17 def initialize(interval, week_start) @interval = interval @week_start = week_start end |
Instance Attribute Details
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
15 16 17 |
# File 'lib/ice_cube/validations/weekly_interval.rb', line 15 def interval @interval end |
#week_start ⇒ Object (readonly)
Returns the value of attribute week_start.
15 16 17 |
# File 'lib/ice_cube/validations/weekly_interval.rb', line 15 def week_start @week_start end |
Instance Method Details
#build_hash(builder) ⇒ Object
45 46 47 48 |
# File 'lib/ice_cube/validations/weekly_interval.rb', line 45 def build_hash(builder) builder[:interval] = interval builder[:week_start] = TimeUtil.sym_to_wday(week_start) end |
#build_ical(builder) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/ice_cube/validations/weekly_interval.rb', line 50 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
41 42 43 |
# File 'lib/ice_cube/validations/weekly_interval.rb', line 41 def build_s(builder) builder.base = IceCube::I18n.t('ice_cube.each_week', count: interval) end |
#dst_adjust? ⇒ Boolean
26 27 28 |
# File 'lib/ice_cube/validations/weekly_interval.rb', line 26 def dst_adjust? true end |
#type ⇒ Object
22 23 24 |
# File 'lib/ice_cube/validations/weekly_interval.rb', line 22 def type :day end |
#validate(step_time, start_time) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ice_cube/validations/weekly_interval.rb', line 30 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 |