Module: MultiXml::FileLike

Defined in:
lib/multi_xml/file_like.rb

Overview

Mixin that provides file-like metadata to StringIO objects

Used when parsing base64-encoded file content from XML. Adds original_filename and content_type attributes to StringIO.

Examples:

Extending a StringIO

io = StringIO.new("file content")
io.extend(MultiXml::FileLike)
io.original_filename = "document.pdf"
io.content_type = "application/pdf"

Constant Summary collapse

DEFAULT_FILENAME =

Default filename when none is specified

Returns:

  • (String)

    the default filename "untitled"

"untitled".freeze
DEFAULT_CONTENT_TYPE =

Default content type when none is specified

Returns:

  • (String)

    the default MIME type "application/octet-stream"

"application/octet-stream".freeze

Instance Attribute Summary collapse

Instance Attribute Details

#content_typeString

Get the content type

Examples:

Get content type

io.content_type #=> "application/pdf"

Returns:

  • (String)

    the content type or "application/octet-stream" if not set



58
59
60
# File 'lib/multi_xml/file_like.rb', line 58

def content_type
  @content_type || DEFAULT_CONTENT_TYPE
end

#original_filenameString

Get the original filename

Examples:

Get filename

io.original_filename #=> "document.pdf"

Returns:

  • (String)

    the original filename or "untitled" if not set



48
49
50
# File 'lib/multi_xml/file_like.rb', line 48

def original_filename
  @original_filename || DEFAULT_FILENAME
end