Class: Roqua::Healthy::MessageCleaner

Inherits:
Object
  • Object
show all
Defined in:
lib/roqua/healthy/message_cleaner.rb

Instance Method Summary collapse

Constructor Details

#initialize(message) ⇒ MessageCleaner

Returns a new instance of MessageCleaner.



5
6
7
# File 'lib/roqua/healthy/message_cleaner.rb', line 5

def initialize(message)
  @message = message
end

Instance Method Details

#clean(thing) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/roqua/healthy/message_cleaner.rb', line 13

def clean(thing)
  case thing
  when Hash
    clean_hash(thing)
  when Array
    clean_array(thing)
  when String
    clean_string(thing)
  else
    thing
  end
end

#clean_array(array) ⇒ Object



33
34
35
36
37
# File 'lib/roqua/healthy/message_cleaner.rb', line 33

def clean_array(array)
  array.map do |value|
    clean(value)
  end
end

#clean_hash(hash) ⇒ Object



26
27
28
29
30
31
# File 'lib/roqua/healthy/message_cleaner.rb', line 26

def clean_hash(hash)
  hash.each do |key, value|
    hash[key] = clean(value)
  end
  hash
end

#clean_string(string) ⇒ Object



39
40
41
42
# File 'lib/roqua/healthy/message_cleaner.rb', line 39

def clean_string(string)
  return '' if string == '""'
  string.strip
end

#messageObject



9
10
11
# File 'lib/roqua/healthy/message_cleaner.rb', line 9

def message
  clean_hash(@message)
end