Class: Achoo::Temporal::Timespan

Inherits:
Range
  • Object
show all
Defined in:
lib/achoo/temporal/timespan.rb

Direct Known Subclasses

OpenTimespan

Instance Method Summary collapse

Constructor Details

#initialize(start, end_) ⇒ Timespan

Returns a new instance of Timespan.

Raises:

  • (ArgumentError)


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

Returns:

  • (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

Returns:

  • (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_sObject



14
15
16
# File 'lib/achoo/temporal/timespan.rb', line 14

def to_s
  "(%s) %s" % [duration_string, from_to_string]
end