Class: SOAP::Attachment

Inherits:
Object show all
Defined in:
lib/soap/attachment.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string_or_readable = nil) ⇒ Attachment

Returns a new instance of Attachment.



37
38
39
40
41
42
# File 'lib/soap/attachment.rb', line 37

def initialize(string_or_readable = nil)
  @string_or_readable = string_or_readable
  @contenttype = "application/octet-stream"
  @contentid = nil
  @content = nil
end

Instance Attribute Details

#contenttypeObject

Returns the value of attribute contenttype.



35
36
37
# File 'lib/soap/attachment.rb', line 35

def contenttype
  @contenttype
end

#ioObject (readonly)

Returns the value of attribute io.



34
35
36
# File 'lib/soap/attachment.rb', line 34

def io
  @io
end

Class Method Details

.contentid(obj) ⇒ Object



78
79
80
81
# File 'lib/soap/attachment.rb', line 78

def self.contentid(obj)
  # this needs to be fixed
  [obj.__id__.to_s, Process.pid.to_s].join('.')
end

.mime_contentid(obj) ⇒ Object



83
84
85
# File 'lib/soap/attachment.rb', line 83

def self.mime_contentid(obj)
  '<' + contentid(obj) + '>'
end

Instance Method Details

#contentObject



56
57
58
59
60
61
62
# File 'lib/soap/attachment.rb', line 56

def content
  if @content == nil and @string_or_readable != nil
    @content = @string_or_readable.respond_to?(:read) ?
	@string_or_readable.read : @string_or_readable
  end
  @content
end

#contentidObject



44
45
46
# File 'lib/soap/attachment.rb', line 44

def contentid
  @contentid ||= Attachment.contentid(self)
end

#contentid=(contentid) ⇒ Object



48
49
50
# File 'lib/soap/attachment.rb', line 48

def contentid=(contentid)
  @contentid = contentid
end

#mime_contentidObject



52
53
54
# File 'lib/soap/attachment.rb', line 52

def mime_contentid
  '<' + contentid + '>'
end

#save(filename) ⇒ Object



72
73
74
75
76
# File 'lib/soap/attachment.rb', line 72

def save(filename)
  File.open(filename, "wb") do |f|
    write(f)
  end
end

#to_sObject



64
65
66
# File 'lib/soap/attachment.rb', line 64

def to_s
  content
end

#write(out) ⇒ Object



68
69
70
# File 'lib/soap/attachment.rb', line 68

def write(out)
  out.write(content)
end