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.
Instance Method Summary collapse
- #build_hash(builder) ⇒ Object
- #build_ical(builder) ⇒ Object
- #build_s(builder) ⇒ Object
-
#initialize(interval) ⇒ Validation
constructor
A new instance of Validation.
- #type ⇒ Object
- #validate(time, schedule) ⇒ Object
Constructor Details
#initialize(interval) ⇒ Validation
Returns a new instance of Validation.
32 33 34 |
# File 'lib/ice_cube/validations/weekly_interval.rb', line 32 def initialize(interval) @interval = interval end |
Instance Attribute Details
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
14 15 16 |
# File 'lib/ice_cube/validations/weekly_interval.rb', line 14 def interval @interval end |
Instance Method Details
#build_hash(builder) ⇒ Object
28 29 30 |
# File 'lib/ice_cube/validations/weekly_interval.rb', line 28 def build_hash(builder) builder[:interval] = interval end |
#build_ical(builder) ⇒ Object
24 25 26 |
# File 'lib/ice_cube/validations/weekly_interval.rb', line 24 def build_ical(builder) builder['FREQ'] << 'WEEKLY' end |
#build_s(builder) ⇒ Object
20 21 22 |
# File 'lib/ice_cube/validations/weekly_interval.rb', line 20 def build_s(builder) builder.base = interval == 1 ? 'Weekly' : "Every #{interval} weeks" end |
#type ⇒ Object
16 17 18 |
# File 'lib/ice_cube/validations/weekly_interval.rb', line 16 def type :day end |
#validate(time, schedule) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/ice_cube/validations/weekly_interval.rb', line 36 def validate(time, schedule) date = Date.new(time.year, time.month, time.day) st = schedule.start_time start_date = Date.new(st.year, st.month, st.day) weeks = ((date - date.wday) - (start_date - start_date.wday)) / 7 unless weeks % interval == 0 (interval - (weeks % interval)) * 7 end end |