Sha256: f3500abc5dbefa4fd97fee54ee894f4836fbda14610c696f1fe15f9be8daa016

Contents?: true

Size: 771 Bytes

Versions: 3

Compression:

Stored size: 771 Bytes

Contents

module Roqua
  module Healthy
    class MessageCleaner
      def initialize(message)
        @message = message
      end

      def message
        clean_hash(@message)
      end

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

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

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

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
roqua-healthy-1.4.1 lib/roqua/healthy/message_cleaner.rb
roqua-healthy-1.3.0 lib/roqua/healthy/message_cleaner.rb
roqua-healthy-1.2.1 lib/roqua/healthy/message_cleaner.rb