Sha256: 78040f45948d41312ab8f6b76749eb1cdc2e5b7465b0a8ba2f20564d8df268bb

Contents?: true

Size: 741 Bytes

Versions: 3

Compression:

Stored size: 741 Bytes

Contents

# frozen_string_literal: true

module Mail
  module Jdec
    class Detector
      class << self
        def detect(text)
          return if text.nil?

          detected = CharlockHolmes::EncodingDetector.detect(text)
          detected if trusty?(detected) && find_encoding(detected)
        end

        private
    
        def find_encoding(detected)
          Encoding.find(detected[:encoding])
        rescue
          nil
        end

        def trusty?(detected)
          detected.key?(:type) &&
            detected.key?(:encoding) &&
            detected[:confidence].to_i >= Jdec.autodetect_confidence &&
            !Jdec.autodetect_skip_charsets.include?(detected[:encoding].downcase)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mail-jdec-1.1.2 lib/mail/jdec/detector.rb
mail-jdec-1.1.1 lib/mail/jdec/detector.rb
mail-jdec-1.1.0 lib/mail/jdec/detector.rb