Class: Stash::Wrapper::StashFile

Inherits:
Object
  • Object
show all
Includes:
XML::Mapping
Defined in:
lib/stash/wrapper/stash_file.rb

Overview

Mapping for <st:file>.

Instance Method Summary collapse

Constructor Details

#initialize(pathname:, size_bytes:, mime_type:) ⇒ StashFile

Creates a new Stash::Wrapper::StashFile object

Parameters:

  • pathname (String) —

    the pathname

  • size_bytes (Integer) —

    the size in bytes

  • mime_type (MIME::Type, String) —

    the MIME type, as either a MIME::Type object or a string



22
23
24
25
26
# File 'lib/stash/wrapper/stash_file.rb', line 22

def initialize(pathname:, size_bytes:, mime_type:)
  self.pathname = pathname
  self.size_bytes = size_bytes
  self.mime_type = mime_type
end

Instance Method Details

#mime_type=(value) ⇒ Object

Sets the MIME type, converting from a string if necessary

Parameters:

  • value (MIME::Type, String) —

    the MIME type, as either a MIME::Type object or a string



31
32
33
# File 'lib/stash/wrapper/stash_file.rb', line 31

def mime_type=(value)
  @mime_type = to_mime_type(value)
end

#size_bytes ⇒ Integer

Gets the size in bytes, extracting it from the Stash::Wrapper::Size

Returns:

  • (Integer) —

    the size in bytes



43
44
45
# File 'lib/stash/wrapper/stash_file.rb', line 43

def size_bytes
  size.size
end

#size_bytes=(bytes) ⇒ Object

Sets the size in bytes, expanding it to a Stash::Wrapper::Size object

Parameters:

  • bytes (Integer) —

    the size in bytes



37
38
39
# File 'lib/stash/wrapper/stash_file.rb', line 37

def size_bytes=(bytes)
  self.size = Size.new(bytes: bytes)
end