Class: IceCube::Enumerator
- Inherits:
-
Enumerator
- Object
- Enumerator
- IceCube::Enumerator
- Defined in:
- lib/ice_cube/enumerator.rb
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(schedule, opening_time, closing_time) ⇒ Enumerator
constructor
A new instance of Enumerator.
- #next ⇒ Object
Constructor Details
#initialize(schedule, opening_time, closing_time) ⇒ Enumerator
Returns a new instance of Enumerator.
4 5 6 7 8 9 10 |
# File 'lib/ice_cube/enumerator.rb', line 4 def initialize(schedule, opening_time, closing_time) @schedule = schedule @opening_time = TimeUtil.ensure_time(opening_time) @closing_time = TimeUtil.ensure_time(closing_time) align_opening_time @cursor = @opening_time end |
Instance Method Details
#each ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/ice_cube/enumerator.rb', line 12 def each return to_enum unless block_given? while res = self.next && @closing_time.nil? || res <= @closing_time yield Occurrence.new(res, res + schedule.duration) end raise StopIteration end |
#next ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ice_cube/enumerator.rb', line 20 def next t1 = full_required? ? schedule.start_time : opening_time Enumerator.new do |yielder| loop do t1.tap { |t| puts "LDA #{t}" + " #{File.basename(__FILE__)}:#{__LINE__}" } break unless (t0 = next_time(t1, closing_time).tap { |t| puts "LDB #{t}" + " #{File.basename(__FILE__)}:#{__LINE__}" }) break if closing_time && t0 > closing_time yielder << (block_given? ? block.call(t0) : t0) if t0 >= opening_time break unless (t1 = next_time(t0 + 1, closing_time)) break if closing_time && t1 > closing_time if TimeUtil.same_clock?(t0, t1) && recurrence_rules.any?(&:dst_adjust?) wind_back_dst next (t1 += 1) end yielder << (block_given? ? block.call(t1) : t1) if t1 >= opening_time next (t1 += 1) end end end |