Module: Dokkit::Resource::FilenameHelper

Included in:
Data, Document
Defined in:
lib/dokkit/resource/filenamehelper.rb

Overview

This is a helper module that aims to simplify operation with filenames.

Instance Method Summary collapse

Instance Method Details

#filename_helper(fn, dir, new_dir, new_ext = '') ⇒ Object

Return a filename transformed in its directory part and (optionally) in its extension.

fn

is the source filename.

dir

is the directory part to be changed.

new_dir

is the new directory part that substitutes dir.

new_ext

is the (optionally) new extension for the fn.



22
23
24
25
26
27
# File 'lib/dokkit/resource/filenamehelper.rb', line 22

def filename_helper(fn, dir, new_dir, new_ext = '')
  ext = File.extname(fn).sub(/^\./,'') # strip leading dot
  new_fn = fn.sub(/#{dir}/, new_dir)
  new_fn = new_fn << new_ext unless new_ext.empty?
  new_fn
end