Module: What::Helpers

Defined in:
lib/what/helpers.rb

Constant Summary collapse

HEALTH =

Take an array of healths and determine overall health, on the principle that overall health == the worst sub-health.

%w(ok warning alert)

Class Method Summary collapse

Class Method Details

.best_health(healths) ⇒ Object



14
15
16
# File 'lib/what/helpers.rb', line 14

def self.best_health(healths)
  ordered_healths(healths).first
end

.camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/what/helpers.rb', line 19

def self.camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
  if first_letter_in_uppercase
    lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
  else
    lower_case_and_underscored_word.to_s[0].chr.downcase + camelize(lower_case_and_underscored_word)[1..-1]
  end
end

.curl(uri) {|open(uri).read| ... } ⇒ Object

Yields:

  • (open(uri).read)


37
38
39
# File 'lib/what/helpers.rb', line 37

def self.curl(uri)
  yield(open(uri).read)
end

.overall_health(healths) ⇒ Object



6
7
8
# File 'lib/what/helpers.rb', line 6

def self.overall_health(healths)
  worst_health(healths)
end

.process_linesObject

Performs a simple strip of invalid UTF-8 characters on the output of ‘ps aux’



42
43
44
# File 'lib/what/helpers.rb', line 42

def self.process_lines
  `ps aux`.encode('UTF-16', invalid: :replace, undef: :replace).encode('UTF-8').split("\n")
end

.underscore(camel_cased_word) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/what/helpers.rb', line 27

def self.underscore(camel_cased_word)
  word = camel_cased_word.to_s.dup
  word.gsub!(/::/, '/')
  word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
  word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
  word.tr!("-", "_")
  word.downcase!
  word
end

.worst_health(healths) ⇒ Object



10
11
12
# File 'lib/what/helpers.rb', line 10

def self.worst_health(healths)
  ordered_healths(healths).last
end