Class: CmisServer::ContentStream
- Inherits:
-
Object
- Object
- CmisServer::ContentStream
- Defined in:
- lib/cmis_server/content_stream.rb
Instance Attribute Summary collapse
-
#base64 ⇒ Object
Returns the value of attribute base64.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#id ⇒ Object
Returns the value of attribute id.
-
#media_type ⇒ Object
Returns the value of attribute media_type.
Instance Method Summary collapse
- #content ⇒ Object
- #default_extensions ⇒ Object
-
#initialize(id: nil, base64: nil, media_type: nil, filename: nil) ⇒ ContentStream
constructor
A new instance of ContentStream.
- #length ⇒ Object
- #tempfile(name = 'tempfile') ⇒ Object
- #with_tempfile(&block) ⇒ Object
Constructor Details
#initialize(id: nil, base64: nil, media_type: nil, filename: nil) ⇒ ContentStream
Returns a new instance of ContentStream.
13 14 15 16 17 18 |
# File 'lib/cmis_server/content_stream.rb', line 13 def initialize(id: nil, base64: nil, media_type: nil, filename: nil) @media_type=media_type @base64 =base64 @id =id @filename =filename end |
Instance Attribute Details
#base64 ⇒ Object
Returns the value of attribute base64.
9 10 11 |
# File 'lib/cmis_server/content_stream.rb', line 9 def base64 @base64 end |
#filename ⇒ Object
Returns the value of attribute filename.
10 11 12 |
# File 'lib/cmis_server/content_stream.rb', line 10 def filename @filename end |
#id ⇒ Object
Returns the value of attribute id.
11 12 13 |
# File 'lib/cmis_server/content_stream.rb', line 11 def id @id end |
#media_type ⇒ Object
Returns the value of attribute media_type.
8 9 10 |
# File 'lib/cmis_server/content_stream.rb', line 8 def media_type @media_type end |
Instance Method Details
#content ⇒ Object
28 29 30 |
# File 'lib/cmis_server/content_stream.rb', line 28 def content Base64.decode64(self.base64) end |
#default_extensions ⇒ Object
24 25 26 |
# File 'lib/cmis_server/content_stream.rb', line 24 def default_extensions MIME::Types[self.media_type].first&.extensions&.first||'txt' end |
#length ⇒ Object
20 21 22 |
# File 'lib/cmis_server/content_stream.rb', line 20 def length content.bytesize end |
#tempfile(name = 'tempfile') ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/cmis_server/content_stream.rb', line 32 def tempfile(name='tempfile') t=Tempfile.new([name, ".#{default_extensions}"]) t.binmode t.write(self.content) t.close t.open t end |
#with_tempfile(&block) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/cmis_server/content_stream.rb', line 41 def with_tempfile(&block) temp_file=self.tempfile begin block.call(temp_file) ensure temp_file.close temp_file.unlink end end |