Class: Gooby::Duration
- Inherits:
-
GoobyObject
- Object
- GoobyObject
- Gooby::Duration
- Defined in:
- lib/gooby_duration.rb
Overview
Instances of this class represent the contents of a Forerunner extract
<Duration> tag, such as:
<Duration>PT507.870S</Duration>
Instance Attribute Summary collapse
-
#minutes ⇒ Object
Returns the value of attribute minutes.
-
#mmss ⇒ Object
Returns the value of attribute mmss.
-
#rawdata ⇒ Object
Returns the value of attribute rawdata.
-
#seconds ⇒ Object
Returns the value of attribute seconds.
Instance Method Summary collapse
-
#initialize(raw) ⇒ Duration
constructor
Constructor; arg is a String like ‘PT507.870S’.
-
#print_string ⇒ Object
Return a String with state values for debugging.
- #to_s ⇒ 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) ⇒ Duration
Constructor; arg is a String like ‘PT507.870S’.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/gooby_duration.rb', line 22 def initialize(raw) if raw @rawdata = scrub("#{raw}") @seconds = @rawdata.to_f @minutes = @seconds / 60 @base_min = @minutes.floor @frac_min = @minutes - @base_min @frac_sec = @frac_min * 60 @mmss = '' if (@base_min < 10) @mmss << "0#{@base_min}:" else @mmss << "#{@base_min}:" end if (@frac_sec < 10) @mmss << "0#{@frac_sec}" else @mmss << "#{@frac_sec}" end if (@mmss.size > 8) @mmss = @mmss[0..8] end else @rawdata = '' @seconds = invalidDistance @minutes = invalidMinutes @mmss = '??:??.?' end end |
Instance Attribute Details
#minutes ⇒ Object
Returns the value of attribute minutes.
19 20 21 |
# File 'lib/gooby_duration.rb', line 19 def minutes @minutes end |
#mmss ⇒ Object
Returns the value of attribute mmss.
19 20 21 |
# File 'lib/gooby_duration.rb', line 19 def mmss @mmss end |
#rawdata ⇒ Object
Returns the value of attribute rawdata.
19 20 21 |
# File 'lib/gooby_duration.rb', line 19 def rawdata @rawdata end |
#seconds ⇒ Object
Returns the value of attribute seconds.
19 20 21 |
# File 'lib/gooby_duration.rb', line 19 def seconds @seconds end |
Instance Method Details
#print_string ⇒ Object
Return a String with state values for debugging.
80 81 82 |
# File 'lib/gooby_duration.rb', line 80 def print_string "Duration: #{@rawdata} sec: #{@seconds} min: #{@minutes} mmss: #{@mmss} bm: #{@base_min} fm: #{@frac_min} fs: #{@frac_sec}" end |
#to_s ⇒ Object
75 76 77 |
# File 'lib/gooby_duration.rb', line 75 def to_s "#{@mmss}" end |