Class: Gooby::DtTm
- Inherits:
-
GoobyObject
- Object
- GoobyObject
- Gooby::DtTm
- Defined in:
- lib/gooby_dttm.rb
Overview
Instances of this class represent a Date and Time as parsed from a value
such as '2006-01-15T13:41:40Z' in an XML file produced by a GPS device.
It wrappers both a DateTime and Time object.
Instance Attribute Summary collapse
-
#dateTime ⇒ Object
Returns the value of attribute dateTime.
-
#rawdata ⇒ Object
Returns the value of attribute rawdata.
-
#time ⇒ Object
Returns the value of attribute time.
-
#valid ⇒ Object
Returns the value of attribute valid.
Instance Method Summary collapse
- #hh_mm_ss ⇒ Object
-
#hhmmss_diff(anotherDtTm) ⇒ Object
Calculate and return time diff in ‘hh:mm:ss’ format.
-
#initialize(raw) ⇒ DtTm
constructor
Constructor; arg is a String like ‘2006-01-15T13:41:40Z’.
-
#print_string ⇒ Object
Return a String with state values for debugging.
-
#seconds_diff(anotherDtTm) ⇒ Object
Calculates and returns diff between another instance.
-
#to_i ⇒ Object
Return @time.to_i.
- #to_s ⇒ Object
- #yyyy_mm_dd ⇒ Object
- #yyyy_mm_dd_hh_mm_ss(delim = ' ') ⇒ Object
Methods included from GoobyKernel
#character_align, #default_delimiter, #invalid_altitude, #invalid_heartbeat, #invalid_latitude, #invalid_longitude, #invalid_time, #project_author, #project_copyright, #project_date, #project_embedded_comment, #project_license, #project_name, #project_version_number, #project_year, #read_as_ascii_lines, #read_lines, #strip_lines, #tokenize
Constructor Details
#initialize(raw) ⇒ DtTm
Constructor; arg is a String like ‘2006-01-15T13:41:40Z’.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/gooby_dttm.rb', line 22 def initialize(raw) if raw @rawdata = raw.strip if @rawdata.size > 18 @date_time = DateTime.parse(@rawdata[0..18]) @time = Time.parse(@date_time.to_s) @valid = true else @valid = false end else @rawdata = '' @valid = false end end |
Instance Attribute Details
#dateTime ⇒ Object
Returns the value of attribute dateTime.
19 20 21 |
# File 'lib/gooby_dttm.rb', line 19 def dateTime @dateTime end |
#rawdata ⇒ Object
Returns the value of attribute rawdata.
19 20 21 |
# File 'lib/gooby_dttm.rb', line 19 def rawdata @rawdata end |
#time ⇒ Object
Returns the value of attribute time.
19 20 21 |
# File 'lib/gooby_dttm.rb', line 19 def time @time end |
#valid ⇒ Object
Returns the value of attribute valid.
19 20 21 |
# File 'lib/gooby_dttm.rb', line 19 def valid @valid end |
Instance Method Details
#hh_mm_ss ⇒ Object
62 63 64 |
# File 'lib/gooby_dttm.rb', line 62 def hh_mm_ss @time.strftime("%H:%M:%S") end |
#hhmmss_diff(anotherDtTm) ⇒ Object
Calculate and return time diff in ‘hh:mm:ss’ format.
67 68 69 70 71 72 73 74 |
# File 'lib/gooby_dttm.rb', line 67 def hhmmss_diff(anotherDtTm) if anotherDtTm t = @time - (anotherDtTm.to_i) t.strftime("%H:%M:%S") else '00:00:00' end end |
#print_string ⇒ Object
Return a String with state values for debugging.
81 82 83 |
# File 'lib/gooby_dttm.rb', line 81 def print_string "DtTm: #{yyyy_mm_dd_hh_mm_ss} #{to_i} #{@rawdata}" end |
#seconds_diff(anotherDtTm) ⇒ Object
Calculates and returns diff between another instance.
46 47 48 49 50 51 52 |
# File 'lib/gooby_dttm.rb', line 46 def seconds_diff(anotherDtTm) if anotherDtTm to_i - anotherDtTm.to_i else invalid_time end end |
#to_i ⇒ Object
Return @time.to_i
41 42 43 |
# File 'lib/gooby_dttm.rb', line 41 def to_i() (@time) ? @time.to_i : invalid_time end |
#to_s ⇒ Object
76 77 78 |
# File 'lib/gooby_dttm.rb', line 76 def to_s "#{@rawdata}" end |
#yyyy_mm_dd ⇒ Object
54 55 56 |
# File 'lib/gooby_dttm.rb', line 54 def yyyy_mm_dd @time.strftime("%Y-%m-%d") end |
#yyyy_mm_dd_hh_mm_ss(delim = ' ') ⇒ Object
58 59 60 |
# File 'lib/gooby_dttm.rb', line 58 def yyyy_mm_dd_hh_mm_ss(delim=' ') @time.strftime("%Y-%m-%d#{delim}%H:%M:%S") end |