Class: Ourtime
- Inherits:
-
Object
- Object
- Ourtime
- Defined in:
- lib/ndr_support/ourtime.rb
Overview
Convert a string into a time value (timestamp) (helped by String.thetime)
Instance Attribute Summary collapse
-
#thetime ⇒ Object
readonly
Returns the value of attribute thetime.
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(x = nil) ⇒ Ourtime
constructor
A new instance of Ourtime.
- #to_s ⇒ Object
Constructor Details
#initialize(x = nil) ⇒ Ourtime
Returns a new instance of Ourtime.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/ndr_support/ourtime.rb', line 9 def initialize(x = nil) if x.is_a?(Time) @thetime = x elsif x.is_a?(Date) @thetime = x.to_time elsif x.is_a?(String) self.source = x else @thetime = nil end end |
Instance Attribute Details
#thetime ⇒ Object (readonly)
Returns the value of attribute thetime.
7 8 9 |
# File 'lib/ndr_support/ourtime.rb', line 7 def thetime @thetime end |
Instance Method Details
#empty? ⇒ Boolean
25 26 27 28 |
# File 'lib/ndr_support/ourtime.rb', line 25 def empty? # An unspecified time will be empty. A valid or invalid time will not. @thetime.nil? && @source.blank? end |
#to_s ⇒ Object
21 22 23 |
# File 'lib/ndr_support/ourtime.rb', line 21 def to_s @thetime ? @thetime.to_time.to_s(:ui) : '' end |