Module: CleanFilenames
- Extended by:
- Methadone::CLILogging
- Defined in:
- lib/clean_filenames.rb,
lib/clean_filenames/version.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{}
- VERSION =
"1.0.1"
Class Method Summary collapse
Class Method Details
.convert_name(name = nil, ignore_levels = 0) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/clean_filenames.rb', line 19 def self.convert_name(name=nil, ignore_levels=0) # When performing the split below, if there is a leading file # separator on the file name, an empty string will be in the # leading resulting array, just as needed. However, the number of # levels expected needs to be increased to accomodate this fact. ignore_levels += 1 if name[0] == File::SEPARATOR parts = name.dup.to_s.split(File::SEPARATOR) leading_parts = [] (0...ignore_levels).each {|l| leading_parts.push parts.shift} converted_parts = parts.map do |p| extension = File.extname(p) basename = File.basename(p,extension) basename = basename.to_url "#{basename}#{extension}" end File.join(leading_parts + converted_parts) end |
.run(*args) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/clean_filenames.rb', line 12 def self.run(*args) = DEFAULT_OPTIONS.merge(args.pop) if args.last.is_a?(Hash) ignore_levels = .fetch("ignore-levels", "0").to_i name = args.shift if args.first.is_a?(String) self.convert_name(name,ignore_levels) end |