Class: Mu::Xtractr::Content

Inherits:
Object
  • Object
show all
Defined in:
lib/mu/xtractr/content.rb

Overview

end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message) ⇒ Content

:nodoc:



44
45
46
47
48
49
# File 'lib/mu/xtractr/content.rb', line 44

def initialize message # :nodoc:
    @name    = "content.#{message.stream.flow.id}.#{message.index}"
    @type    = 'application/unknown'
    @body    = nil
    @message = message
end

Instance Attribute Details

#bodyObject

The actual body of the content (gunzip’d PDF file, for example)



42
43
44
# File 'lib/mu/xtractr/content.rb', line 42

def body
  @body
end

#encodingObject

The encoding (base64, gzip, deflate, etc) of this content.



33
34
35
# File 'lib/mu/xtractr/content.rb', line 33

def encoding
  @encoding
end

#messageObject (readonly)

The message from which this content was extracted.



39
40
41
# File 'lib/mu/xtractr/content.rb', line 39

def message
  @message
end

#nameObject

The name of the content (like a jpeg or pdf file).



30
31
32
# File 'lib/mu/xtractr/content.rb', line 30

def name
  @name
end

#typeObject

The mime type of this content.



36
37
38
# File 'lib/mu/xtractr/content.rb', line 36

def type
  @type
end

Instance Method Details

#inspectObject

:nodoc:



62
63
64
65
# File 'lib/mu/xtractr/content.rb', line 62

def inspect # :nodoc:
    preview = body[0..32].inspect
    "#<content #{name} #{type} #{encoding} #{preview}>"
end

#save(filename = nil) ⇒ Object

Save the content to a file. If the filename is not provided then the content name is used instead. This is a convenience method used for method chaining.

flow.stream.contents.first.save


55
56
57
58
59
60
# File 'lib/mu/xtractr/content.rb', line 55

def save filename=nil
    open(filename || name, "w") do |ios|
        ios.write body
    end
    return self
end