lib/hiccup/enumerable/schedule_enumerator.rb in hiccup-0.5.0 vs lib/hiccup/enumerable/schedule_enumerator.rb in hiccup-0.5.1

- old
+ new

@@ -1,6 +1,5 @@ - module Hiccup module Enumerable class ScheduleEnumerator def self.enum_for(schedule) @@ -17,27 +16,25 @@ def initialize(schedule, seed_date) @schedule = schedule @ends = schedule.ends? @seed_date = seed_date @seed_date = seed_date.to_date if seed_date.respond_to?(:to_date) - @seed_date = start_date if (seed_date < start_date) - @seed_date = end_date if (ends? && seed_date > end_date) @cursor = nil end attr_reader :schedule, :seed_date, :cursor def next - @cursor = started? ? advance! : first_occurrence_on_or_after(seed_date) + @cursor = started? ? advance! : first_occurrence_on_or_after(seed_start_date) return nil if ends? && @cursor > end_date @cursor end def prev - @cursor = started? ? rewind! : first_occurrence_on_or_before(seed_date) + @cursor = started? ? rewind! : first_occurrence_on_or_before(seed_end_date) return nil if @cursor < start_date @cursor end @@ -62,9 +59,21 @@ def leap_year?(year) return false unless (year % 4).zero? return (year % 400).zero? if (year % 100).zero? true + end + + + + def seed_start_date + return start_date if (seed_date < start_date) + seed_date + end + + def seed_end_date + return end_date if (ends? && seed_date > end_date) + seed_date end # These two methods DO assume that