Class: ChupaText::Formatters::MIME

Inherits:
Hash
  • Object
show all
Defined in:
lib/chupa-text/formatters/mime.rb

Instance Method Summary collapse

Methods inherited from Hash

#format_extracted, #format_start

Constructor Details

#initialize(output) ⇒ MIME

Returns a new instance of MIME.



25
26
27
28
# File 'lib/chupa-text/formatters/mime.rb', line 25

def initialize(output)
  super()
  @output = output
end

Instance Method Details

#format_finish(data) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/chupa-text/formatters/mime.rb', line 30

def format_finish(data)
  formatted = super

  @output << "MIME-Version: 1.0\r\n"
  format_hash(formatted, ["texts"])
  texts = formatted["texts"]
  boundary = Digest::SHA1.hexdigest(data.uri.to_s)
  @output << "Content-Type: multipart/mixed; boundary=#{boundary}\r\n"
  texts.each do |text|
    @output << "\r\n--#{boundary}\r\n"
    format_text(text)
  end
  @output << "\r\n--#{boundary}--\r\n"
end