class TimeInterval::RepeatingInterval

Attributes

length[R]

Public Class Methods

new(time_with_duration, times) click to toggle source
# File lib/time_interval/repeating_interval.rb, line 21
def initialize(time_with_duration, times)
  @time_with_duration = time_with_duration
  @length = times
end
parse(iso8601) click to toggle source
# File lib/time_interval/repeating_interval.rb, line 3
def self.parse(iso8601)
  recurrence, time_with_duration_string = iso8601.split('/', 2)

  times = if recurrence.match(/^R(\d+)/)
            Regexp.last_match[1].to_i
          else
            Float::INFINITY
          end

  fail ArgumentError if times == 0

  new TimeWithDuration.parse(time_with_duration_string), times
end

Public Instance Methods

each(&block) click to toggle source
# File lib/time_interval/repeating_interval.rb, line 26
def each(&block)
  enumerator.each(&block)
end
iso8601() click to toggle source
# File lib/time_interval/repeating_interval.rb, line 30
def iso8601
  if length == Float::INFINITY
    "R/#{@time_with_duration.iso8601}"
  else
    "R#{length}/#{@time_with_duration.iso8601}"
  end
end

Private Instance Methods

enumerator() click to toggle source
# File lib/time_interval/repeating_interval.rb, line 40
def enumerator
  @enumerator ||= Enumerator::Lazy.new(0...length) do |yielder, i|
    if i == 0
      yielder.yield @time_with_duration
    else
      interval = @time_with_duration
      i.times { interval = interval.step }
      yielder.yield interval
    end
  end
end