Class: M26::ElapsedTime

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#hhObject

Returns the value of attribute hh.



13
14
15
# File 'lib/m26_elapsed_time.rb', line 13

def hh
  @hh
end

#mmObject

Returns the value of attribute mm.



13
14
15
# File 'lib/m26_elapsed_time.rb', line 13

def mm
  @mm
end

#secsObject

Returns the value of attribute secs.



13
14
15
# File 'lib/m26_elapsed_time.rb', line 13

def secs
  @secs
end

#ssObject

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_hhmmssObject



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_hoursObject



26
27
28
# File 'lib/m26_elapsed_time.rb', line 26

def as_hours
  @secs / SECONDS_PER_HOUR.to_f
end


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_sObject



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