Sha256: 99e7040989ae48c2cee9832ca8f12d457a9a25b7edc52dd266e15343c88a64ea

Contents?: true

Size: 801 Bytes

Versions: 17

Compression:

Stored size: 801 Bytes

Contents

# frozen_string_literal: true
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

17 entries across 17 versions & 1 rubygems

Version Path
roqua-healthy-1.6.0 lib/roqua/healthy/message_cleaner.rb
roqua-healthy-1.5.13 lib/roqua/healthy/message_cleaner.rb
roqua-healthy-1.5.12 lib/roqua/healthy/message_cleaner.rb
roqua-healthy-1.5.11 lib/roqua/healthy/message_cleaner.rb
roqua-healthy-1.5.10 lib/roqua/healthy/message_cleaner.rb
roqua-healthy-1.5.9 lib/roqua/healthy/message_cleaner.rb
roqua-healthy-1.5.8 lib/roqua/healthy/message_cleaner.rb
roqua-healthy-1.5.7 lib/roqua/healthy/message_cleaner.rb
roqua-healthy-1.5.6 lib/roqua/healthy/message_cleaner.rb
roqua-healthy-1.5.5 lib/roqua/healthy/message_cleaner.rb
roqua-healthy-1.5.4 lib/roqua/healthy/message_cleaner.rb
roqua-healthy-1.5.3 lib/roqua/healthy/message_cleaner.rb
roqua-healthy-1.5.2 lib/roqua/healthy/message_cleaner.rb
roqua-healthy-1.5.1 lib/roqua/healthy/message_cleaner.rb
roqua-healthy-1.5.0 lib/roqua/healthy/message_cleaner.rb
roqua-healthy-1.4.3 lib/roqua/healthy/message_cleaner.rb
roqua-healthy-1.4.2 lib/roqua/healthy/message_cleaner.rb