Class: Numeric

Inherits:
Object show all
Defined in:
lib/notifu/mixins.rb

Instance Method Summary collapse

Instance Method Details

#durationObject


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/notifu/mixins.rb', line 9

def duration
  secs  = self.to_int
  mins  = secs / 60
  hours = mins / 60
  days  = hours / 24

  if days > 0
    "#{days}d, #{hours % 24}h, #{mins % 60}min, #{secs % 60}s"
  elsif hours > 0
    "#{hours}h, #{mins % 60}min, #{secs % 60}s"
  elsif mins > 0
    "#{mins}min, #{secs % 60}s"
  elsif secs >= 0
    "#{secs}s"
  end
end

#to_stateObject


26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/notifu/mixins.rb', line 26

def to_state
  case self.to_int
  when 0
    return "OK"
  when 1
    return "WARNING"
  when 2
    return "CRITICAL"
  else
    return "UNKNOWN [#{self.to_s}]"
  end
end