Class: File
- Inherits:
-
Object
- Object
- File
- Defined in:
- lib/absolute_renamer/libs/file.rb
Overview
Extension of existing File class.
Class Method Summary collapse
-
.extname(path, dot = 1) ⇒ Object
Returns the extension of a file.
Class Method Details
.extname(path, dot = 1) ⇒ Object
Returns the extension of a file. path: the path of the file dot: starting from the end, number of dots to count before cuting extension.
6 7 8 9 10 |
# File 'lib/absolute_renamer/libs/file.rb', line 6 def extname(path, dot = 1) pattern = (0...dot).inject('') { |pat,x| pat << '\.[^\.]+' } << '$' ext = File.basename(path).match(pattern).to_s ext.empty? ? "" : ext[1..ext.length] end |