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.


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

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

Instance Attribute Details

#contenttypeObject

Returns the value of attribute contenttype


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

def contenttype
  @contenttype
end

#ioObject (readonly)

Returns the value of attribute io


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

def io
  @io
end

Class Method Details

.contentid(obj) ⇒ Object


76
77
78
79
# File 'lib/soap/attachment.rb', line 76

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

.mime_contentid(obj) ⇒ Object


81
82
83
# File 'lib/soap/attachment.rb', line 81

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

Instance Method Details

#contentObject


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

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


42
43
44
# File 'lib/soap/attachment.rb', line 42

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

#contentid=(contentid) ⇒ Object


46
47
48
# File 'lib/soap/attachment.rb', line 46

def contentid=(contentid)
  @contentid = contentid
end

#mime_contentidObject


50
51
52
# File 'lib/soap/attachment.rb', line 50

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

#save(filename) ⇒ Object


70
71
72
73
74
# File 'lib/soap/attachment.rb', line 70

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

#to_sObject


62
63
64
# File 'lib/soap/attachment.rb', line 62

def to_s
  content
end

#write(out) ⇒ Object


66
67
68
# File 'lib/soap/attachment.rb', line 66

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