Class: Timerage::TimeInterval
- Inherits:
-
Range
- Object
- Range
- Timerage::TimeInterval
- Defined in:
- lib/timerage/time_interval.rb
Overview
A range of time. The exposes the Range like interface.
Class Method Summary collapse
-
.iso8601(str) ⇒ Object
Returns a new TimeInterval representation of the iso8601 interval represented by the specified string.
Instance Method Summary collapse
-
#initialize(*args) ⇒ TimeInterval
constructor
A new instance of TimeInterval.
-
#iso8601(*args) ⇒ Object
Returns an ISO8601 interval representation of self Takes same args as Time#iso8601.
- #step(n, &blk) ⇒ Object
Constructor Details
#initialize(*args) ⇒ TimeInterval
Returns a new instance of TimeInterval.
6 7 8 9 10 11 12 13 14 |
# File 'lib/timerage/time_interval.rb', line 6 def initialize(*args) rng = if rangeish?(args.first) args.first else Range.new(*args) end super rng end |
Class Method Details
.iso8601(str) ⇒ Object
Returns a new TimeInterval representation of the iso8601 interval represented by the specified string.
--
Currently this only supports <begin>/<end> style time intervals.
72 73 74 75 76 77 |
# File 'lib/timerage/time_interval.rb', line 72 def self.iso8601(str) new *str.split("/").map{|s| Time.iso8601(s)} rescue ArgumentError raise ArgumentError, "Invalid iso8601 interval: #{str.inspect}" end |
Instance Method Details
#iso8601(*args) ⇒ Object
Returns an ISO8601 interval representation of self Takes same args as Time#iso8601
28 29 30 |
# File 'lib/timerage/time_interval.rb', line 28 def iso8601(*args) "#{self.begin.iso8601(*args)}/#{self.end.iso8601(*args)}" end |
#step(n, &blk) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/timerage/time_interval.rb', line 18 def step(n, &blk) if block_given? time_enumerator(n).each(&blk) else time_enumerator(n) end end |