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.



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

def initialize(message)
  @message = message
end

Instance Method Details

#clean(thing) ⇒ Object



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

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



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

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

#clean_hash(hash) ⇒ Object



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

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

#clean_string(string) ⇒ Object



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

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

#messageObject



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

def message
  clean_hash(@message)
end