Class: Tepoch::Util

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

Class Method Summary collapse

Class Method Details

.pluralize(number) ⇒ Object



21
22
23
24
# File 'lib/tepoch/util.rb', line 21

def self.pluralize number
  return "s" unless number == 1
  return ""
end

.seconds_to_string(s) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/tepoch/util.rb', line 3

def self.seconds_to_string(s)

  # d = days, h = hours, m = minutes, s = seconds
  m = (s / 60).floor
  s = s % 60
  h = (m / 60).floor
  m = m % 60
  d = (h / 24).floor
  h = h % 24

  output = "#{s} second#{Util.pluralize(s)}" if (s > 0)
  output = "#{m} minute#{Util.pluralize(m)}, #{s} second#{Util.pluralize(s)}" if (m > 0)
  output = "#{h} hour#{Util.pluralize(h)}, #{m} minute#{Util.pluralize(m)}, #{s} second#{Util.pluralize(s)}" if (h > 0)
  output = "#{d} day#{Util.pluralize(d)}, #{h} hour#{Util.pluralize(h)}, #{m} minute#{Util.pluralize(m)}, #{s} second#{Util.pluralize(s)}" if (d > 0)

  return output
end