module Nuggets::File::ExtMixin

Public Instance Methods

chomp_ext(path) → aString click to toggle source

Returns a copy of path with its file extension removed.

# File lib/nuggets/file/ext_mixin.rb, line 35
def chomp_ext(path, ext = extname(path))
  path.chomp(ext)
end
chomp_ext!(path) → aString | nil click to toggle source

Modifies path in place as described for chomp_ext, returning path, or nil if no modifications were made.

# File lib/nuggets/file/ext_mixin.rb, line 44
def chomp_ext!(path, ext = extname(path))
  path.chomp!(ext)
end
set_ext(path, new_ext) → aString click to toggle source

Returns a copy of path with its file extension removed and new_ext appended. Like sub_ext, but also applies when file extension is not present.

# File lib/nuggets/file/ext_mixin.rb, line 72
def set_ext(path, new_ext, ext = extname(path))
  chomp_ext(path, ext) << new_ext
end
set_ext!(path, new_ext) → aString click to toggle source

Modifies path in place as described for set_ext, returning path.

# File lib/nuggets/file/ext_mixin.rb, line 81
def set_ext!(path, new_ext, ext = extname(path))
  chomp_ext!(path, ext); path << new_ext
end
sub_ext(path, new_ext) → aString click to toggle source

Returns a copy of path with its file extension replaced with new_ext (if present; see also set_ext).

# File lib/nuggets/file/ext_mixin.rb, line 53
def sub_ext(path, new_ext, ext = extname(path))
  sub_ext!(_path = path.dup, new_ext, ext); _path
end
sub_ext!(path, new_ext) → aString | nil click to toggle source

Modifies path in place as described for sub_ext, returning path, or nil if no modifications were made.

# File lib/nuggets/file/ext_mixin.rb, line 62
def sub_ext!(path, new_ext, ext = extname(path))
  path << new_ext if chomp_ext!(path, ext)
end