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