Sha256: 7271a9f8df25d457c3dd673c319b462a66ba97d5ea269983ab9241f299f0d244

Contents?: true

Size: 1.32 KB

Versions: 240

Compression:

Stored size: 1.32 KB

Contents

# encoding: utf-8
module Mail
  module Encodings
    class TransferEncoding
      NAME = ''

      PRIORITY = -1

      def self.can_transport?(enc)
        enc = Encodings.get_name(enc)
        if Encodings.defined? enc
          Encodings.get_encoding(enc).new.is_a? self
        else
          false
        end
      end

      def self.can_encode?(enc)
        can_transport? enc 
      end

      def self.cost(str)
        raise "Unimplemented"
      end

      def self.to_s
        self::NAME
      end

      def self.get_best_compatible(source_encoding, str)
        if self.can_transport? source_encoding then
            source_encoding 
        else
            choices = []
            Encodings.get_all.each do |enc|
                choices << enc if self.can_transport? enc and enc.can_encode? source_encoding
            end
            best = nil 
            best_cost = 100
            choices.each do |enc|
                this_cost = enc.cost str
                if this_cost < best_cost then
                    best_cost = this_cost
                    best = enc
                elsif this_cost == best_cost then 
                    best = enc if enc::PRIORITY < best::PRIORITY
                end
            end
            best
        end
      end

      def to_s
        self.class.to_s
      end
    end
  end
end

Version data entries

240 entries across 197 versions & 23 rubygems

Version Path
mail-2.5.5 lib/mail/encodings/transfer_encoding.rb
mail-2.5.5.rc1 lib/mail/encodings/transfer_encoding.rb
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/mail-2.6.3/lib/mail/encodings/transfer_encoding.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/mail-2.6.3/lib/mail/encodings/transfer_encoding.rb
tdiary-4.2.1 vendor/bundle/ruby/2.3.0/gems/mail-2.6.3/lib/mail/encodings/transfer_encoding.rb
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/mail-2.6.3/lib/mail/encodings/transfer_encoding.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/mail-2.6.3/lib/mail/encodings/transfer_encoding.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/mail-2.6.3/lib/mail/encodings/transfer_encoding.rb
classiccms-0.7.5 vendor/bundle/gems/mail-2.4.4/lib/mail/encodings/transfer_encoding.rb
classiccms-0.7.4 vendor/bundle/gems/mail-2.4.4/lib/mail/encodings/transfer_encoding.rb
classiccms-0.7.3 vendor/bundle/gems/mail-2.4.4/lib/mail/encodings/transfer_encoding.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/mail-2.6.3/lib/mail/encodings/transfer_encoding.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/mail-2.6.3/lib/mail/encodings/transfer_encoding.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/mail-2.6.3/lib/mail/encodings/transfer_encoding.rb
active_mailer-0.0.10 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/encodings/transfer_encoding.rb
shoppe-paypal-1.1.0 vendor/bundle/ruby/2.1.0/gems/mail-2.6.3/lib/mail/encodings/transfer_encoding.rb
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/mail-2.4.4/lib/mail/encodings/transfer_encoding.rb
mail-2.6.3 lib/mail/encodings/transfer_encoding.rb
mail-portertech-2.6.2.edge lib/mail/encodings/transfer_encoding.rb
mail-2.6.1 lib/mail/encodings/transfer_encoding.rb