class ChupaText::Formatters::MIME

Public Class Methods

new(output, options={}) click to toggle source
Calls superclass method ChupaText::Formatters::Hash::new
# File lib/chupa-text/formatters/mime.rb, line 25
def initialize(output, options={})
  super()
  @output = output
  @boundary = options[:boundary]
end

Public Instance Methods

format_finish(data) click to toggle source
# File lib/chupa-text/formatters/mime.rb, line 31
def format_finish(data)
  formatted = super

  @output << "MIME-Version: 1.0\r\n"
  format_hash(formatted, ["texts"])
  texts = formatted["texts"]
  boundary = @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

Private Instance Methods

format_hash(hash, ignore_keys) click to toggle source
# File lib/chupa-text/formatters/mime.rb, line 47
def format_hash(hash, ignore_keys)
  hash.each do |key, value|
    next if ignore_keys.include?(key)
    @output << "#{key}: #{value}\r\n"
  end
end
format_text(hash) click to toggle source
# File lib/chupa-text/formatters/mime.rb, line 54
def format_text(hash)
  format_hash(hash, ["body"])
  body = hash["body"]
  if body
    @output << "\r\n"
    @output << body
  end
end