Module: Texd::Attachment

Defined in:
lib/texd/attachment.rb

Defined Under Namespace

Classes: Base, Dynamic, File, Reference, RenameError

Class Method Summary collapse

Class Method Details

.name(path, with_extension = true) ⇒ String

Computes the file name of a given path, and returns it with or without file extension.

Parameters:

  • path (String, Pathname)

    A Pathname instance or just a plain file name.

  • with_extension (Boolean) (defaults to: true)

    If true, returns the file path’s basename unmodified, otherwise the file extension, including its “.”, is removed.

Returns:

  • (String)

    File path with or without extension.



167
168
169
170
171
172
173
174
175
# File 'lib/texd/attachment.rb', line 167

def self.name(path, with_extension = true) # rubocop:disable Style/OptionalBooleanParameter
  basename = ::File.basename(path)
  return basename if with_extension

  dot = basename.rindex(".")
  return basename if dot == 0 # file starts with "."

  basename.slice(0, dot)
end