Class: Numeric

Inherits:
Object show all
Defined in:
lib/corelib/numeric/core.rb

Instance Method Summary collapse

Instance Method Details

#to_days_hours_minutes_secondsObject

Assumes numeric value is in seconds



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/corelib/numeric/core.rb', line 9

def to_days_hours_minutes_seconds
  total_seconds = self.to_i

  days = total_seconds / 86400
  hours = (total_seconds / 3600) - (days * 24)
  minutes = (total_seconds / 60) - (hours * 60) - (days * 1440)
  seconds = total_seconds % 60

  display = ''
  display_concat = ''
  if days > 0
    display = display + display_concat + "#{days}d"
    display_concat = ' '
  end
  if hours > 0 || display.length > 0
    display = display + display_concat + "#{hours}h"
    display_concat = ' '
  end
  if minutes > 0 || display.length > 0
    display = display + display_concat + "#{minutes}m"
    display_concat = ' '
  end
  display = display + display_concat + "#{seconds}s"
  display
end

#to_hours_minutes(if_zero = "") ⇒ Object

Assumes numeric value is in seconds



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/corelib/numeric/core.rb', line 36

def to_hours_minutes(if_zero="")
  total_seconds = self.to_i

  return if_zero if total_seconds < 60

  hours = (total_seconds / 3600)
  minutes = (total_seconds / 60) - (hours * 60)

  display = ''
  display_concat = ''

  if hours > 0
    display = display + "#{hours}h"
    display_concat = ' '
  end
  if minutes > 0 || display.length > 0
    display = display + display_concat + "#{minutes}m"
  end
  display
end

#to_yes_no(options = {}) ⇒ Object

format accepts (C-Capitalized, U-Uppercase, L-Lowercase)



4
5
6
# File 'lib/corelib/numeric/core.rb', line 4

def to_yes_no(options={})
  (self == 1 || self == 1.0).to_yes_no(options)
end