Sha256: 0e8a6cfc903c2442b9bac6f078df71c5f644927a13a32bbaecd8112e572444fd

Contents?: true

Size: 805 Bytes

Versions: 18

Compression:

Stored size: 805 Bytes

Contents

# Allows any object (if supported) to have all related
# strings encoded in place to UTF-8.
module UTF8Encoding
  module ObjectSupport
    # Recursively ensure the correct encoding is being used:
    def ensure_utf8_object!(object)
      case object
      when String
        ensure_utf8!(object)
      when Hash
        ensure_utf8_hash!(object)
      when Array
        ensure_utf8_array!(object)
      else
        object
      end
    end

    # Ensures all values of the given `hash` are UTF-8, where possible.
    def ensure_utf8_hash!(hash)
      hash.each_value { |value| ensure_utf8_object!(value) }
    end

    # Ensures all elements of the given `array` are UTF-8, where possible.
    def ensure_utf8_array!(array)
      array.each { |element| ensure_utf8_object!(element) }
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
ndr_support-5.10.4 lib/ndr_support/utf8_encoding/object_support.rb
ndr_support-5.10.3 lib/ndr_support/utf8_encoding/object_support.rb
ndr_support-5.10.2 lib/ndr_support/utf8_encoding/object_support.rb
ndr_support-5.10.1 lib/ndr_support/utf8_encoding/object_support.rb
ndr_support-5.10.0 lib/ndr_support/utf8_encoding/object_support.rb
ndr_support-5.9.7 lib/ndr_support/utf8_encoding/object_support.rb
ndr_support-5.9.6 lib/ndr_support/utf8_encoding/object_support.rb
ndr_support-5.9.5 lib/ndr_support/utf8_encoding/object_support.rb
ndr_support-5.9.4 lib/ndr_support/utf8_encoding/object_support.rb
ndr_support-5.9.3 lib/ndr_support/utf8_encoding/object_support.rb
ndr_support-5.9.2 lib/ndr_support/utf8_encoding/object_support.rb
ndr_support-5.9.1 lib/ndr_support/utf8_encoding/object_support.rb
ndr_support-5.9.0 lib/ndr_support/utf8_encoding/object_support.rb
ndr_support-5.8.4 lib/ndr_support/utf8_encoding/object_support.rb
ndr_support-5.8.3 lib/ndr_support/utf8_encoding/object_support.rb
ndr_support-5.8.2 lib/ndr_support/utf8_encoding/object_support.rb
ndr_support-5.8.1 lib/ndr_support/utf8_encoding/object_support.rb
ndr_support-5.8.0 lib/ndr_support/utf8_encoding/object_support.rb