lib/reservation/weekly.rb in reservation-0.0.5 vs lib/reservation/weekly.rb in reservation-0.0.6
- old
+ new
@@ -28,14 +28,21 @@
def initialize patterns
self.wdays = []
patterns.each { |pattern|
day = pattern["day"]
+ dayno = (day =~ /\d+/) ? day.to_i : DAY_MAP[day]
+
nth_of_month = parse_nth_of_month pattern["nth_of_month"]
- start = HourMinute.parse pattern["start"]
- finish = HourMinute.parse pattern["finish"]
- self.wdays << Daily.new(DAY_MAP[day], nth_of_month, Interval.new(start, finish))
+ if pattern["intervals"]
+ intervals = Interval.parse(pattern["intervals"])
+ self.wdays.concat intervals.map { |i| Daily.new(dayno, nth_of_month, i) }
+ else
+ start = HourMinute.parse pattern["start"]
+ finish = HourMinute.parse pattern["finish"]
+ self.wdays << Daily.new(dayno, nth_of_month, Interval.new(start, finish))
+ end
}
end
# true if there exists a Daily corresponding to this event's weekday, with
# an Interval corresponding to this event's start and finish times;