Class: Numeric

Inherits:
Object
  • Object
show all
Defined in:
lib/dic.rb

Instance Method Summary collapse

Instance Method Details

#durationObject


1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
# File 'lib/dic.rb', line 1155

def duration
  rest, secs = self.divmod( 60 )  # self is the time difference t2 - t1
  rest, mins = rest.divmod( 60 )
  days, hours = rest.divmod( 24 )
  # the above can be factored out as:
  # days, hours, mins, secs = self.duration_as_arr
  #
  # this is not so great, because it could include zero values:
  # self.duration_as_arr.zip ['Days','Hours','Minutes','Seconds']).flatten.join ' '
  result = []
  result << "#{days} Days" if days > 0
  result << "#{hours} Hours" if hours > 0
  result << "#{mins} Minutes" if mins > 0
  result << "#{secs} Seconds" if secs > 0
  return result.join(' ')
end