Class: TimeInterval::RepeatingInterval
- Inherits:
-
Object
- Object
- TimeInterval::RepeatingInterval
- Includes:
- Enumerable
- Defined in:
- lib/time_interval/repeating_interval.rb
Instance Attribute Summary collapse
-
#length ⇒ Object
readonly
Returns the value of attribute length.
Class Method Summary collapse
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(time_with_duration, times) ⇒ RepeatingInterval
constructor
A new instance of RepeatingInterval.
- #iso8601 ⇒ Object
Constructor Details
#initialize(time_with_duration, times) ⇒ RepeatingInterval
Returns a new instance of RepeatingInterval.
21 22 23 24 |
# File 'lib/time_interval/repeating_interval.rb', line 21 def initialize(time_with_duration, times) @time_with_duration = time_with_duration @length = times end |
Instance Attribute Details
#length ⇒ Object (readonly)
Returns the value of attribute length.
19 20 21 |
# File 'lib/time_interval/repeating_interval.rb', line 19 def length @length end |
Class Method Details
.parse(iso8601) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# 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 |
Instance Method Details
#each(&block) ⇒ Object
26 27 28 |
# File 'lib/time_interval/repeating_interval.rb', line 26 def each(&block) enumerator.each(&block) end |
#iso8601 ⇒ Object
30 31 32 33 34 35 36 |
# 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 |