Class: TimeSpan::RelativeTime
- Inherits:
-
Object
- Object
- TimeSpan::RelativeTime
- Defined in:
- lib/time_span.rb
Overview
class RelativeTime #
#
public methods: #
comparators: < <= == != >= > #
work on any two RelativeTime objects on the same TimeLine #
positioned? #
true if a RelativeTime has been put on a TimeLine # #
colinear_with?(RelativeTime.new) #
true if both RelativeTime objects are positioned and on same TimeLine #
#
protected method: #
valid_and_comparable_with?(RelativeTime) #
true if #
#
diff cannot be done, it makes no sense, due to the fuzziness #
#
RelativeTime must be within a TimeLine #
Instance Attribute Summary collapse
-
#reference_to ⇒ Object
Object (PORO) reference_to should respond_to? :to_s.
-
#time_line ⇒ Object
TimeLine on which this RelativeTime is placed.
Instance Method Summary collapse
- #clone ⇒ Object
-
#colinear_with?(other_relative_time) ⇒ Boolean
True if both are on the same TimeLine.
-
#initialize(tline, ref) ⇒ Object
constructor
create a realtive time *within a time_line* after position.
-
#meth ⇒ Boolean
comparator methods any method on fixnum with 1 RelativeTime param can be in the list below.
-
#positioned? ⇒ Boolean
True if self has been properly placed on a TimeLine.
-
#to_s ⇒ String
The string representation of referenced object.
Constructor Details
#initialize(tline, ref) ⇒ Object
create a realtive time *within a time_line* after position
421 422 423 424 |
# File 'lib/time_span.rb', line 421 def initialize tline, ref @time_line= tline @reference_to= ref end |
Instance Attribute Details
#reference_to ⇒ Object
Object (PORO) reference_to should respond_to? :to_s
415 416 417 |
# File 'lib/time_span.rb', line 415 def reference_to @reference_to end |
#time_line ⇒ Object
TimeLine on which this RelativeTime is placed
414 415 416 |
# File 'lib/time_span.rb', line 414 def time_line @time_line end |
Instance Method Details
#clone ⇒ Object
427 428 429 |
# File 'lib/time_span.rb', line 427 def clone raise NotImplementedError, "Cannot use base Ruby clone which can create illegal objects by gem rules." end |
#colinear_with?(other_relative_time) ⇒ Boolean
Returns true if both are on the same TimeLine.
456 457 458 |
# File 'lib/time_span.rb', line 456 def colinear_with?(other_relative_time) other_relative_time.kind_of?(self.class) && other_relative_time.positioned? && positioned? && time_line.equal?(other_relative_time.time_line) end |
#meth ⇒ Boolean
comparator methods any method on fixnum with 1 RelativeTime param can be in the list below
442 443 444 445 446 447 |
# File 'lib/time_span.rb', line 442 %w{< <= == != >= >}.each{ |meth| self.send(:define_method, meth) {|other_relative_time| raise ArgumentError, "can only compare to other times on the same time_line." unless valid_and_comparable_with?(other_relative_time) # can NOT compare across TimeLines self.time_line.position_of(self).send(meth, other_relative_time.time_line.position_of(other_relative_time)) } } |
#positioned? ⇒ Boolean
Returns true if self has been properly placed on a TimeLine.
450 451 452 |
# File 'lib/time_span.rb', line 450 def positioned? self.time_line && self.time_line.indices_of.include?(self) end |
#to_s ⇒ String
Returns the string representation of referenced object.
434 435 436 |
# File 'lib/time_span.rb', line 434 def to_s @reference_to.to_s end |