Completed
Push — master ( c5afbf...1a678e )
by John
01:03
created

Text.initialize()   B

Complexity

Conditions 6

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 1
Metric Value
cc 6
c 5
b 0
f 1
dl 0
loc 17
rs 8
1
require 'mime'
2
3
module MIMEBuilder
4
  class Text
5
    attr_accessor :mime
6
    attr_accessor :text
7
8
    def initialize(text, opts = {})
9
      @text = text
10
11
      if opts.key?(:content_type) && opts[:content_type].to_s.length>0
12
        content_type = opts[:content_type]
13
        if content_type =~ /^text\/([^\/]+)$/i
14
          @mime = MIME::Text.new(text, $1.downcase)
15
        else
16
          raise "Unknown Content Type: " + opts[:content_type].to_s
17
        end
18
      else
19
        @mime = MIME::Text.new(text, 'plain')
20
      end
21
22
      @mime.headers.delete('Content-Id') \
23
        if opts.key?(:content_id_disable) && opts[:content_id_disable]
24
    end
25
  end
26
end
27