Class: Chronic::Span
- Inherits:
-
Range
- Object
- Range
- Chronic::Span
- Defined in:
- lib/chronic/chronic.rb
Overview
A Span represents a range of time. Since this class extends Range, you can use #begin and #end to get the beginning and ending times of the span (they will be of class Time)
Instance Method Summary collapse
-
#+(seconds) ⇒ Object
Add a number of seconds to this span, returning the resulting Span.
-
#-(seconds) ⇒ Object
Subtract a number of seconds to this span, returning the resulting Span.
-
#initialize(range_begin, range_end) ⇒ Span
constructor
A new instance of Span.
-
#to_s ⇒ Object
Prints this span in a nice fashion.
-
#width ⇒ Object
Returns the width of this span in seconds.
Constructor Details
#initialize(range_begin, range_end) ⇒ Span
Returns a new instance of Span.
251 252 253 254 |
# File 'lib/chronic/chronic.rb', line 251 def initialize(range_begin, range_end) # Use exclusive range. super(range_begin, range_end, true) end |
Instance Method Details
#+(seconds) ⇒ Object
Add a number of seconds to this span, returning the resulting Span
263 264 265 |
# File 'lib/chronic/chronic.rb', line 263 def +(seconds) Span.new(self.begin + seconds, self.end + seconds) end |
#-(seconds) ⇒ Object
Subtract a number of seconds to this span, returning the resulting Span
269 270 271 |
# File 'lib/chronic/chronic.rb', line 269 def -(seconds) self + -seconds end |
#to_s ⇒ Object
Prints this span in a nice fashion
274 275 276 |
# File 'lib/chronic/chronic.rb', line 274 def to_s '(' << self.begin.to_s << '...' << self.end.to_s << ')' end |
#width ⇒ Object
Returns the width of this span in seconds
257 258 259 |
# File 'lib/chronic/chronic.rb', line 257 def width (self.end - self.begin).to_i end |