Class: Mail::Part

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

Direct Known Subclasses

Attachment, Mail

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Part

Returns a new instance of Part.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/mail/part.rb', line 5

def initialize(options)
  if options.kind_of?(String)
    @part_str = options
    set_header(options)
  elsif options.kind_of?(Hash)
    @part_str = options[:content]
    @header = Header.new(:content_type => options[:content_type])
  else
    @header = Header.new
  end
end

Instance Attribute Details

#headerObject (readonly)

Returns the value of attribute header.



3
4
5
# File 'lib/mail/part.rb', line 3

def header
  @header
end

Instance Method Details

#contentObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/mail/part.rb', line 25

def content
  buffer = String.new
  body_found = false
  @part_str.each_line do |line|
    if body_found
      buffer << line
    end
    body_found = true if !body_found && line.strip.empty?
  end
  return buffer
end

#empty?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/mail/part.rb', line 21

def empty?
  @part_str.empty?
end

#to_sObject



17
18
19
# File 'lib/mail/part.rb', line 17

def to_s
  @part_str
end