Class: Texd::Attachment::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/texd/attachment.rb

Direct Known Subclasses

File, Reference

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, rename, serial) ⇒ Base

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Base.

Parameters:

  • path (Pathname)

    see AttachmentList#attach

  • rename (Boolean, String)

    see AttachmentList#attach

  • serial (Integer)

    number of files currently in the parent AttachmentList (used for renaming purposes)



198
199
200
201
202
203
204
205
206
207
# File 'lib/texd/attachment.rb', line 198

def initialize(path, rename, serial)
  @absolute_path = path.expand_path

  @name = case rename
  when true   then format("att%04d%s", serial, path.extname)
  when false  then path.basename.to_s
  when String then rename
  else raise RenameError, rename
  end
end

Instance Attribute Details

#absolute_pathObject (readonly)

absolute path to attachment on local file system



191
192
193
# File 'lib/texd/attachment.rb', line 191

def absolute_path
  @absolute_path
end

Instance Method Details

#name(with_extension = true) ⇒ String

Returns the (renamed) output file name. When ‘with_extension` is `true`, the file extension is chopped.

Parameters:

  • with_extension (Boolean) (defaults to: true)

Returns:

  • (String)

    output file name



214
215
216
# File 'lib/texd/attachment.rb', line 214

def name(with_extension = true) # rubocop:disable Style/OptionalBooleanParameter
  Attachment.name(@name, with_extension)
end