Class: M26::ElapsedTime
- Inherits:
-
Object
- Object
- M26::ElapsedTime
- Includes:
- Constants
- Defined in:
- lib/m26_elapsed_time.rb
Constant Summary
Constants included from Constants
Constants::AUTHOR, Constants::DATE, Constants::EMAIL, Constants::KILOMETERS_PER_MILE, Constants::MILES_PER_KILOMETER, Constants::SECONDS_PER_HOUR, Constants::UOM_KILOMETERS, Constants::UOM_MILES, Constants::UOM_YARDS, Constants::VERSION, Constants::YARDS_PER_KILOMETER, Constants::YARDS_PER_MILE
Instance Attribute Summary collapse
-
#hh ⇒ Object
Returns the value of attribute hh.
-
#mm ⇒ Object
Returns the value of attribute mm.
-
#secs ⇒ Object
Returns the value of attribute secs.
-
#ss ⇒ Object
Returns the value of attribute ss.
Instance Method Summary collapse
- #as_hhmmss ⇒ Object
- #as_hours ⇒ Object
-
#initialize(raw_val) ⇒ ElapsedTime
constructor
A new instance of ElapsedTime.
- #print_string ⇒ Object
- #subtract(another_instance) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(raw_val) ⇒ ElapsedTime
Returns a new instance of ElapsedTime.
17 18 19 20 21 22 23 24 |
# File 'lib/m26_elapsed_time.rb', line 17 def initialize(raw_val) @hh, @mm, @ss = 0, 0, 0.0; if (raw_val.kind_of? String) initialize_string(raw_val) else initialize_number(raw_val) end end |
Instance Attribute Details
#hh ⇒ Object
Returns the value of attribute hh.
13 14 15 |
# File 'lib/m26_elapsed_time.rb', line 13 def hh @hh end |
#mm ⇒ Object
Returns the value of attribute mm.
13 14 15 |
# File 'lib/m26_elapsed_time.rb', line 13 def mm @mm end |
#secs ⇒ Object
Returns the value of attribute secs.
13 14 15 |
# File 'lib/m26_elapsed_time.rb', line 13 def secs @secs end |
#ss ⇒ Object
Returns the value of attribute ss.
13 14 15 |
# File 'lib/m26_elapsed_time.rb', line 13 def ss @ss end |
Instance Method Details
#as_hhmmss ⇒ Object
30 31 32 |
# File 'lib/m26_elapsed_time.rb', line 30 def as_hhmmss return "#{zero_pad(@hh)}:#{zero_pad(@mm)}:#{zero_pad(@ss)}" end |
#as_hours ⇒ Object
26 27 28 |
# File 'lib/m26_elapsed_time.rb', line 26 def as_hours @secs / SECONDS_PER_HOUR.to_f end |
#print_string ⇒ Object
45 46 47 |
# File 'lib/m26_elapsed_time.rb', line 45 def print_string return to_s << " #{@secs} #{as_hours}" end |
#subtract(another_instance) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/m26_elapsed_time.rb', line 34 def subtract(another_instance) h1 = as_hours h2 = another_instance.as_hours h3 = h1 - h2 ElapsedTime.new(h3 * SECONDS_PER_HOUR) end |
#to_s ⇒ Object
41 42 43 |
# File 'lib/m26_elapsed_time.rb', line 41 def to_s return "ElapsedTime: hh=#{@hh} mm=#{@mm} ss=#{@ss} secs=#{@secs} as_hours=#{as_hours()} as_hhmmss=#{as_hhmmss()}" end |