class TimeSpan::TimeSpan
this class' objects have a starting and ending TimeSpan::RelativeTime
, and both times must be on the same TimeSpan::TimeLine
implements a large selection of comparators, both for start / end times (single time compartors), and also range comparators @author Craig A. Cook
Attributes
TimeSpan::RelativeTime
end time
TimeSpan::RelativeTime
start time
TimeSpan::TimeLine
this TimeSpan
is associated with
Public Class Methods
@param [TimeSpan::RelativeTime] starting_at is when the span starts @param [TimeSpan::RelativeTime] ending_at is when the spa nends @param [TimeSpan::TimeLIne] is the associated TimeLine
@param [String] The name of the TimeSpan
(Actually any Ruby Object for which '#respond_to?(:to_s) == true') @return [Boolean] true if passed arguments are valid to create a TimeSpan
# File lib/time_span.rb, line 25 def initialize(starting_at, ending_at, t_line, nom="(unnamed)") raise ArgumentError, "Cannot make a span unless both points are on the same time_line" unless starting_at.colinear_with?(ending_at) self.starts = starting_at self.ends = ending_at self.time_line = t_line self.time_line.spans << self self.name = nom starting_at.kind_of?(RelativeTime) && ending_at.kind_of?(RelativeTime) && (starting_at <= ending_at) end
Public Instance Methods
tests if one TimeSpan
is not the same as another (on the same TimeLine
– delegated to RelativeTime
) @param (see starts_before?
) @return [Boolean] true if not same as the other
# File lib/time_span.rb, line 170 def != (other_time_span) !end_with(other_time_span) || !starts_with(other_time_span) end
tests if one TimeSpan
ends before another starts (on the same TimeLine
– delegated to RelativeTime
) alias for '#ends_before_other_starts' @param (see starts_before?
) @return [Boolean] true if self ends before another starts
# File lib/time_span.rb, line 178 def < (other_time_span) ends_before_other_starts?(other_time_span) end
tests if one TimeSpan
is the same as another (on the same TimeLine
– delegated to RelativeTime
) @param (see starts_before?
) @return [Boolean] true if same as the other
# File lib/time_span.rb, line 163 def == (other_time_span) ends_with?(other_time_span) && starts_with?(other_time_span) end
tests if one TimeSpan
starts after another ends (on the same TimeLine
– delegated to RelativeTime
) alias for '#starts_after_other_ends' @param (see starts_before?
) @return [Boolean] true if self starts after another ends
# File lib/time_span.rb, line 186 def > (other_time_span) starts_after_other_ends?(other_time_span) end
@raise [NotImplementedError] could create illegal objects by gem rules
# File lib/time_span.rb, line 36 def clone raise NotImplementedError, "Cannot use base Ruby clone which can create illegal objects by gem rules." end
tests if one TimeSpan
is contained within another (on the same TimeLine
– delegated to RelativeTime
) @param (see starts_before?
) @return true if self contained inside another
# File lib/time_span.rb, line 193 def contained_fully_inside?(other_time_span) starts_after?(other_time_span) && ends_before?(other_time_span) end
tests if one TimeSpan
is contained within another, possibly begining as or ends as another (on the same TimeLine
– delegated to RelativeTime
) @param (see starts_before?
) @return true if self contained inside another, including same endpoints
# File lib/time_span.rb, line 200 def contained_inside?(other_time_span) starts_on_or_after?(other_time_span) && ends_on_or_before?(other_time_span) end
tests if one TimeSpan
contains within another (on the same TimeLine
– delegated to RelativeTime
) @param (see starts_before?
) @return true if self contains another
# File lib/time_span.rb, line 214 def contains?(other_time_span) starts_before_or_with?(other_time_span) && ends_on_or_after?(other_time_span) end
tests if one TimeSpan
contains another (on the same TimeLine
– delegated to RelativeTime
) @param (see starts_before?
) @return true if self contains another
# File lib/time_span.rb, line 207 def contains_fully?(other_time_span) starts_before?(other_time_span) && ends_after?(other_time_span) end
returns the 'statuses' for the start and end times @return start and end time statuses in a hash with key is self
# File lib/time_span.rb, line 42 def endpoint_statuses {self => [self.starts.reference_to, self.ends.reference_to]} end
tests if one TimeSpan
ends after another (on the same TimeLine
– delegated to RelativeTime
) @param (see starts_before?
) @return true if self ends after another time_span ends
# File lib/time_span.rb, line 111 def ends_after?(other_time_span) ends > other_time_span.ends end
tests if one TimeSpan
ends at the same time as another starts (on the same TimeLine
– delegated to RelativeTime
) @param (see starts_before?
) @return true if self ends at the same time as another time_span starts (no gap)
# File lib/time_span.rb, line 132 def ends_as_other_starts?(other_time_span) ends == other_time_span.starts end
tests if one TimeSpan
ends before another starts (on the same TimeLine
– delegated to RelativeTime
) @param (see starts_before?
) @return true if self ends before another time_span starts
# File lib/time_span.rb, line 90 def ends_before?(other_time_span) ends < other_time_span.ends end
tests if one TimeSpan
ends before another starts (on the same TimeLine
– delegated to RelativeTime
) @param (see starts_before?
) @return true if self ends before another time_span starts
# File lib/time_span.rb, line 125 def ends_before_other_starts?(other_time_span) ends < other_time_span.starts end
tests if one TimeSpan
ends after or at the same time as another (on the same TimeLine
– delegated to RelativeTime
) @param (see starts_before?
) @return true if self ends after or at the same time as another time_span ends
# File lib/time_span.rb, line 104 def ends_on_or_after?(other_time_span) ends >= other_time_span.ends end
tests if one TimeSpan
end before or at the same time as another ends (on the same TimeLine
– delegated to RelativeTime
) @param (see starts_before?
) @return true if self ends before or at the same time as another time_span ends
# File lib/time_span.rb, line 97 def ends_on_or_before?(other_time_span) ends <= other_time_span.ends end
tests if one TimeSpan
ends at the same time as another (on the same TimeLine
– delegated to RelativeTime
) @param (see starts_before?
) @return true if self ends at the same time as another time_span ends
# File lib/time_span.rb, line 118 def ends_with?(other_time_span) ends == other_time_span.ends end
tests if one TimeSpan
starts after another (on the same TimeLine
– delegated to RelativeTime
) @param (see starts_before?
) @return true if self starts after other_time_span starts
# File lib/time_span.rb, line 62 def starts_after?(other_time_span) starts > other_time_span.starts end
tests if one TimeSpan
ends at the same time as another (on the same TimeLine
– delegated to RelativeTime
) @param (see starts_before?
) @return true if self ends at the same time as another time_span ends
# File lib/time_span.rb, line 139 def starts_after_other_ends?(other_time_span) starts > other_time_span.ends end
tests if one TimeSpan
starts at the same time as another ends (on the same TimeLine
– delegated to RelativeTime
) @param (see starts_before?
) @return true if self starts at the same time as another time_span ends
# File lib/time_span.rb, line 146 def starts_as_other_ends?(other_time_span) starts == other_time_span.ends end
tests if one TimeSpan
starts before another (on the same TimeLine
– delegated to RelativeTime
) @param [TimeSpan::TimeSpan] other_time_span the TimeSpan
being compared to self @return true if self starts before b starts
# File lib/time_span.rb, line 55 def starts_before?(other_time_span) starts < other_time_span.starts end
tests if one TimeSpan
starts before or at the same time as another (on the same TimeLine
– delegated to RelativeTime
) @param (see starts_before?
) @return true if self starts before or at the same time as other_time_span starts
# File lib/time_span.rb, line 83 def starts_before_or_with?(other_time_span) starts <= other_time_span.starts end
tests if one TimeSpan
starts with or after another (on the same TimeLine
– delegated to RelativeTime
) @param (see starts_before?
) @return true if self starts on or after other_time_span starts
# File lib/time_span.rb, line 69 def starts_on_or_after?(other_time_span) starts >= other_time_span.starts end
tests if one TimeSpan
starts at the same time as another (on the same TimeLine
– delegated to RelativeTime
) @param (see starts_before?
) @return true if self starts at the same time as other_time_span starts
# File lib/time_span.rb, line 76 def starts_with?(other_time_span) starts == other_time_span.starts end