Class: IceCube::Validations::DayOfWeek::Validation
- Inherits:
-
Object
- Object
- IceCube::Validations::DayOfWeek::Validation
- Defined in:
- lib/ice_cube/validations/day_of_week.rb
Instance Attribute Summary collapse
-
#day ⇒ Object
readonly
Returns the value of attribute day.
-
#occ ⇒ Object
readonly
Returns the value of attribute occ.
Instance Method Summary collapse
- #build_hash(builder) ⇒ Object
- #build_ical(builder) ⇒ Object
- #build_s(builder) ⇒ Object
-
#initialize(day, occ) ⇒ Validation
constructor
A new instance of Validation.
- #type ⇒ Object
- #validate(time, schedule) ⇒ Object
Constructor Details
#initialize(day, occ) ⇒ Validation
Returns a new instance of Validation.
45 46 47 48 |
# File 'lib/ice_cube/validations/day_of_week.rb', line 45 def initialize(day, occ) @day = day @occ = occ end |
Instance Attribute Details
#day ⇒ Object (readonly)
Returns the value of attribute day.
18 19 20 |
# File 'lib/ice_cube/validations/day_of_week.rb', line 18 def day @day end |
#occ ⇒ Object (readonly)
Returns the value of attribute occ.
18 19 20 |
# File 'lib/ice_cube/validations/day_of_week.rb', line 18 def occ @occ end |
Instance Method Details
#build_hash(builder) ⇒ Object
39 40 41 42 43 |
# File 'lib/ice_cube/validations/day_of_week.rb', line 39 def build_hash(builder) builder.validations[:day_of_week] ||= {} arr = (builder.validations[:day_of_week][day] ||= []) arr << occ end |
#build_ical(builder) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/ice_cube/validations/day_of_week.rb', line 32 def build_ical(builder) ical_day = IcalBuilder.fixnum_to_ical_day(day) # Delete any with this day and no occ first builder['BYDAY'].delete_if { |d| d == ical_day } builder['BYDAY'] << "#{occ}#{ical_day}" end |
#build_s(builder) ⇒ Object
28 29 30 |
# File 'lib/ice_cube/validations/day_of_week.rb', line 28 def build_s(builder) builder.piece(:day_of_week) << "#{StringBuilder.nice_number(occ)} #{Date::DAYNAMES[day]}" end |
#type ⇒ Object
24 25 26 |
# File 'lib/ice_cube/validations/day_of_week.rb', line 24 def type :day end |
#validate(time, schedule) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ice_cube/validations/day_of_week.rb', line 50 def validate(time, schedule) # count the days to the weekday sum = day >= time.wday ? day - time.wday : 7 - time.wday + day wrapper = TimeUtil::TimeWrapper.new(time) wrapper.add :day, sum # and then count the week until a viable occ loop do which_occ, num_occ = TimeUtil.which_occurrence_in_month(wrapper.to_time, day) this_occ = occ < 0 ? num_occ + occ + 1 : occ break if which_occ == this_occ sum += 7 wrapper.add :day, 7 # one week end sum end |