Sha256: 032dc7d91b879ba99ad1b93b93203f63023ec16f94dc1fe0202e831f327c40b6

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

#                                                                          
# File 'filenamehelper.rb' created on 21 apr 2008 at 14:25:47.                    
#
# See 'dokkit.rb' or +LICENSE+ for license information.                      
#                                                                          
# (C) 2006, 2007, 2008 Andrea Fazzi <andrea.fazzi@alca.le.it> (and contributors). 
#                                                                          

module Dokkit
  module Resource
    
    # This is a helper module that aims to simplify operation with
    # filenames.
    module FilenameHelper
    
      # 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+.
      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    
    
    end
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dokkit-0.5.0 lib/dokkit/resource/filenamehelper.rb