Class: Achoo::Temporal::Timespan
- Inherits:
-
Range
- Object
- Range
- Achoo::Temporal::Timespan
- Defined in:
- lib/achoo/temporal/timespan.rb
Direct Known Subclasses
Instance Method Summary collapse
- #contains?(timeish_or_timespan) ⇒ Boolean
-
#initialize(start, end_) ⇒ Timespan
constructor
A new instance of Timespan.
- #overlaps?(timespan) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(start, end_) ⇒ Timespan
Returns a new instance of Timespan.
8 9 10 11 12 |
# File 'lib/achoo/temporal/timespan.rb', line 8 def initialize(start, end_) raise ArgumentError.new('Nil in parameters not allowed') if start.nil? || end_.nil? super(to_time(start), to_time(end_)) end |
Instance Method Details
#contains?(timeish_or_timespan) ⇒ Boolean
18 19 20 21 22 23 24 25 |
# File 'lib/achoo/temporal/timespan.rb', line 18 def contains?(timeish_or_timespan) if timeish_or_timespan.is_a? Timespan time = timeish_or_timespan cover?(time.first) && cover?(time.last) else cover?(to_time(timeish_or_timespan)) end end |
#overlaps?(timespan) ⇒ Boolean
27 28 29 30 |
# File 'lib/achoo/temporal/timespan.rb', line 27 def overlaps?(timespan) cover?(timespan.first) || cover?(timespan.last) || timespan.contains?(self) end |
#to_s ⇒ Object
14 15 16 |
# File 'lib/achoo/temporal/timespan.rb', line 14 def to_s "(%s) %s" % [duration_string, from_to_string] end |