Class: TimeSpan::TimeSpan
- Inherits:
-
Object
- Object
- TimeSpan::TimeSpan
- Defined in:
- lib/time_span.rb
Overview
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
Instance Attribute Summary collapse
-
#ends ⇒ Object
TimeSpan::RelativeTime end time.
-
#name ⇒ Object
Returns the value of attribute name.
-
#starts ⇒ Object
TimeSpan::RelativeTime start time.
-
#time_line ⇒ Object
TimeSpan::TimeLine this TimeSpan is associated with.
Instance Method Summary collapse
-
#!=(other_time_span) ⇒ Boolean
tests if one TimeSpan is not the same as another (on the same TimeLine – delegated to RelativeTime).
-
#<(other_time_span) ⇒ Boolean
tests if one TimeSpan ends before another starts (on the same TimeLine – delegated to RelativeTime) alias for ‘#ends_before_other_starts’.
-
#==(other_time_span) ⇒ Boolean
tests if one TimeSpan is the same as another (on the same TimeLine – delegated to RelativeTime).
-
#>(other_time_span) ⇒ Boolean
tests if one TimeSpan starts after another ends (on the same TimeLine – delegated to RelativeTime) alias for ‘#starts_after_other_ends’.
- #clone ⇒ Object
-
#contained_fully_inside?(other_time_span) ⇒ Boolean
tests if one TimeSpan is contained within another (on the same TimeLine – delegated to RelativeTime).
-
#contained_inside?(other_time_span) ⇒ Boolean
tests if one TimeSpan is contained within another, possibly begining as or ends as another (on the same TimeLine – delegated to RelativeTime).
-
#contains?(other_time_span) ⇒ Boolean
tests if one TimeSpan contains within another (on the same TimeLine – delegated to RelativeTime).
-
#contains_fully?(other_time_span) ⇒ Boolean
tests if one TimeSpan contains another (on the same TimeLine – delegated to RelativeTime).
-
#endpoint_statuses ⇒ Object
returns the ‘statuses’ for the start and end times.
-
#ends_after?(other_time_span) ⇒ Boolean
tests if one TimeSpan ends after another (on the same TimeLine – delegated to RelativeTime).
-
#ends_as_other_starts?(other_time_span) ⇒ Boolean
tests if one TimeSpan ends at the same time as another starts (on the same TimeLine – delegated to RelativeTime).
-
#ends_before?(other_time_span) ⇒ Boolean
tests if one TimeSpan ends before another starts (on the same TimeLine – delegated to RelativeTime).
-
#ends_before_other_starts?(other_time_span) ⇒ Boolean
tests if one TimeSpan ends before another starts (on the same TimeLine – delegated to RelativeTime).
-
#ends_on_or_after?(other_time_span) ⇒ Boolean
tests if one TimeSpan ends after or at the same time as another (on the same TimeLine – delegated to RelativeTime).
-
#ends_on_or_before?(other_time_span) ⇒ Boolean
tests if one TimeSpan end before or at the same time as another ends (on the same TimeLine – delegated to RelativeTime).
-
#ends_with?(other_time_span) ⇒ Boolean
tests if one TimeSpan ends at the same time as another (on the same TimeLine – delegated to RelativeTime).
-
#initialize(starting_at, ending_at, t_line, nom = "(unnamed)") ⇒ Boolean
constructor
True if passed arguments are valid to create a TimeSpan.
-
#starts_after?(other_time_span) ⇒ Boolean
tests if one TimeSpan starts after another (on the same TimeLine – delegated to RelativeTime).
-
#starts_after_other_ends?(other_time_span) ⇒ Boolean
tests if one TimeSpan ends at the same time as another (on the same TimeLine – delegated to RelativeTime).
-
#starts_as_other_ends?(other_time_span) ⇒ Boolean
tests if one TimeSpan starts at the same time as another ends (on the same TimeLine – delegated to RelativeTime).
-
#starts_before?(other_time_span) ⇒ Boolean
tests if one TimeSpan starts before another (on the same TimeLine – delegated to RelativeTime).
-
#starts_before_or_with?(other_time_span) ⇒ Boolean
tests if one TimeSpan starts before or at the same time as another (on the same TimeLine – delegated to RelativeTime).
-
#starts_on_or_after?(other_time_span) ⇒ Boolean
tests if one TimeSpan starts with or after another (on the same TimeLine – delegated to RelativeTime).
-
#starts_with?(other_time_span) ⇒ Boolean
tests if one TimeSpan starts at the same time as another (on the same TimeLine – delegated to RelativeTime).
Constructor Details
#initialize(starting_at, ending_at, t_line, nom = "(unnamed)") ⇒ Boolean
Returns true if passed arguments are valid to create a TimeSpan.
25 26 27 28 29 30 31 32 33 |
# 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 |
Instance Attribute Details
#ends ⇒ Object
TimeSpan::RelativeTime end time
15 16 17 |
# File 'lib/time_span.rb', line 15 def ends @ends end |
#name ⇒ Object
Returns the value of attribute name.
18 19 20 |
# File 'lib/time_span.rb', line 18 def name @name end |
#starts ⇒ Object
TimeSpan::RelativeTime start time
13 14 15 |
# File 'lib/time_span.rb', line 13 def starts @starts end |
#time_line ⇒ Object
TimeSpan::TimeLine this TimeSpan is associated with
17 18 19 |
# File 'lib/time_span.rb', line 17 def time_line @time_line end |
Instance Method Details
#!=(other_time_span) ⇒ Boolean
tests if one TimeSpan is not the same as another (on the same TimeLine – delegated to RelativeTime)
170 171 172 |
# File 'lib/time_span.rb', line 170 def != (other_time_span) !end_with(other_time_span) || !starts_with(other_time_span) end |
#<(other_time_span) ⇒ Boolean
tests if one TimeSpan ends before another starts (on the same TimeLine – delegated to RelativeTime) alias for ‘#ends_before_other_starts’
178 179 180 |
# File 'lib/time_span.rb', line 178 def < (other_time_span) ends_before_other_starts?(other_time_span) end |
#==(other_time_span) ⇒ Boolean
tests if one TimeSpan is the same as another (on the same TimeLine – delegated to RelativeTime)
163 164 165 |
# File 'lib/time_span.rb', line 163 def == (other_time_span) ends_with?(other_time_span) && starts_with?(other_time_span) end |
#>(other_time_span) ⇒ Boolean
tests if one TimeSpan starts after another ends (on the same TimeLine – delegated to RelativeTime) alias for ‘#starts_after_other_ends’
186 187 188 |
# File 'lib/time_span.rb', line 186 def > (other_time_span) starts_after_other_ends?(other_time_span) end |
#clone ⇒ Object
36 37 38 |
# 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 |
#contained_fully_inside?(other_time_span) ⇒ Boolean
tests if one TimeSpan is contained within another (on the same TimeLine – delegated to RelativeTime)
193 194 195 |
# 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 |
#contained_inside?(other_time_span) ⇒ Boolean
tests if one TimeSpan is contained within another, possibly begining as or ends as another (on the same TimeLine – delegated to RelativeTime)
200 201 202 |
# 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 |
#contains?(other_time_span) ⇒ Boolean
tests if one TimeSpan contains within another (on the same TimeLine – delegated to RelativeTime)
214 215 216 |
# 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 |
#contains_fully?(other_time_span) ⇒ Boolean
tests if one TimeSpan contains another (on the same TimeLine – delegated to RelativeTime)
207 208 209 |
# File 'lib/time_span.rb', line 207 def contains_fully?(other_time_span) starts_before?(other_time_span) && ends_after?(other_time_span) end |
#endpoint_statuses ⇒ Object
returns the ‘statuses’ for the start and end times
42 43 44 |
# File 'lib/time_span.rb', line 42 def endpoint_statuses {self => [self.starts.reference_to, self.ends.reference_to]} end |
#ends_after?(other_time_span) ⇒ Boolean
tests if one TimeSpan ends after another (on the same TimeLine – delegated to RelativeTime)
111 112 113 |
# File 'lib/time_span.rb', line 111 def ends_after?(other_time_span) ends > other_time_span.ends end |
#ends_as_other_starts?(other_time_span) ⇒ Boolean
tests if one TimeSpan ends at the same time as another starts (on the same TimeLine – delegated to RelativeTime)
132 133 134 |
# File 'lib/time_span.rb', line 132 def ends_as_other_starts?(other_time_span) ends == other_time_span.starts end |
#ends_before?(other_time_span) ⇒ Boolean
tests if one TimeSpan ends before another starts (on the same TimeLine – delegated to RelativeTime)
90 91 92 |
# File 'lib/time_span.rb', line 90 def ends_before?(other_time_span) ends < other_time_span.ends end |
#ends_before_other_starts?(other_time_span) ⇒ Boolean
tests if one TimeSpan ends before another starts (on the same TimeLine – delegated to RelativeTime)
125 126 127 |
# File 'lib/time_span.rb', line 125 def ends_before_other_starts?(other_time_span) ends < other_time_span.starts end |
#ends_on_or_after?(other_time_span) ⇒ Boolean
tests if one TimeSpan ends after or at the same time as another (on the same TimeLine – delegated to RelativeTime)
104 105 106 |
# File 'lib/time_span.rb', line 104 def ends_on_or_after?(other_time_span) ends >= other_time_span.ends end |
#ends_on_or_before?(other_time_span) ⇒ Boolean
tests if one TimeSpan end before or at the same time as another ends (on the same TimeLine – delegated to RelativeTime)
97 98 99 |
# File 'lib/time_span.rb', line 97 def ends_on_or_before?(other_time_span) ends <= other_time_span.ends end |
#ends_with?(other_time_span) ⇒ Boolean
tests if one TimeSpan ends at the same time as another (on the same TimeLine – delegated to RelativeTime)
118 119 120 |
# File 'lib/time_span.rb', line 118 def ends_with?(other_time_span) ends == other_time_span.ends end |
#starts_after?(other_time_span) ⇒ Boolean
tests if one TimeSpan starts after another (on the same TimeLine – delegated to RelativeTime)
62 63 64 |
# File 'lib/time_span.rb', line 62 def starts_after?(other_time_span) starts > other_time_span.starts end |
#starts_after_other_ends?(other_time_span) ⇒ Boolean
tests if one TimeSpan ends at the same time as another (on the same TimeLine – delegated to RelativeTime)
139 140 141 |
# File 'lib/time_span.rb', line 139 def starts_after_other_ends?(other_time_span) starts > other_time_span.ends end |
#starts_as_other_ends?(other_time_span) ⇒ Boolean
tests if one TimeSpan starts at the same time as another ends (on the same TimeLine – delegated to RelativeTime)
146 147 148 |
# File 'lib/time_span.rb', line 146 def starts_as_other_ends?(other_time_span) starts == other_time_span.ends end |
#starts_before?(other_time_span) ⇒ Boolean
tests if one TimeSpan starts before another (on the same TimeLine – delegated to RelativeTime)
55 56 57 |
# File 'lib/time_span.rb', line 55 def starts_before?(other_time_span) starts < other_time_span.starts end |
#starts_before_or_with?(other_time_span) ⇒ Boolean
tests if one TimeSpan starts before or at the same time as another (on the same TimeLine – delegated to RelativeTime)
83 84 85 |
# File 'lib/time_span.rb', line 83 def starts_before_or_with?(other_time_span) starts <= other_time_span.starts end |
#starts_on_or_after?(other_time_span) ⇒ Boolean
tests if one TimeSpan starts with or after another (on the same TimeLine – delegated to RelativeTime)
69 70 71 |
# File 'lib/time_span.rb', line 69 def starts_on_or_after?(other_time_span) starts >= other_time_span.starts end |
#starts_with?(other_time_span) ⇒ Boolean
tests if one TimeSpan starts at the same time as another (on the same TimeLine – delegated to RelativeTime)
76 77 78 |
# File 'lib/time_span.rb', line 76 def starts_with?(other_time_span) starts == other_time_span.starts end |