Class: Mail::Encodings::TransferEncoding

Inherits:
Object
  • Object
show all
Defined in:
lib/mail/encodings/transfer_encoding.rb

Direct Known Subclasses

Binary

Constant Summary

NAME =
''
PRIORITY =
-1

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.can_encode?(enc) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/mail/encodings/transfer_encoding.rb', line 19

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

.can_transport?(enc) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
17
# File 'lib/mail/encodings/transfer_encoding.rb', line 10

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

.compatible_input?(str) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/mail/encodings/transfer_encoding.rb', line 27

def self.compatible_input?(str)
  true
end

.cost(str) ⇒ Object



23
24
25
# File 'lib/mail/encodings/transfer_encoding.rb', line 23

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

.get_best_compatible(source_encoding, str) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/mail/encodings/transfer_encoding.rb', line 35

def self.get_best_compatible(source_encoding, str)
  if self.can_transport?(source_encoding) && self.compatible_input?(str)
    source_encoding
  else
    choices = Encodings.get_all.select do |enc|
      self.can_transport?(enc) && enc.can_encode?(source_encoding)
    end

    best = nil
    best_cost = nil

    choices.each do |enc|
      # If the current choice cannot be transported safely,
      # give priority to other choices but allow it to be used as a fallback.
      this_cost = enc.cost(str) if enc.compatible_input?(str)

      if !best_cost || (this_cost && this_cost < best_cost)
        best_cost = this_cost
        best = enc
      elsif this_cost == best_cost
        best = enc if enc::PRIORITY < best::PRIORITY
      end
    end

    best
  end
end

.to_sObject



31
32
33
# File 'lib/mail/encodings/transfer_encoding.rb', line 31

def self.to_s
  self::NAME
end

Instance Method Details

#to_sObject



63
64
65
# File 'lib/mail/encodings/transfer_encoding.rb', line 63

def to_s
  self.class.to_s
end