lib/pa/path.rb in pa-1.3.2 vs lib/pa/path.rb in pa-1.3.3

- old
+ new

@@ -17,11 +17,10 @@ DELEGATE_CLASS_METHODS = [:pwd, :dir, :expand, :real, :parent, :relative_to, :shorten, :delete_ext, :add_ext ] module ClassMethods - # Return current work directory # # @return [String] path def pwd2 Dir.getwd @@ -114,33 +113,35 @@ # Return true if a path has the ext. # # @example # - # Pa.has_ext?("foo.txt", ".txt") -> true - # Pa.has_ext?("foo", ".txt") -> false + # Pa.has_ext?("foo.txt", ".epub", ".txt") -> true + # Pa.has_ext?("foo", ".txt") -> false # - def has_ext?(path, ext) - Pa.ext2(get(path)) == ext + def has_ext?(path, *exts) + exts.include? Pa.ext2(get(path)) end # Delete the tail. # # @example # - # Pa.delete_ext2("foo.txt", ".txt") -> "foo" + # Pa.delete_ext2("foo.txt", ".epub", ".txt") -> "foo" # Pa.delete_ext2("foo", ".txt") -> "foo" # Pa.delete_ext2("foo.epub", ".txt") -> "foo.epub" # - def delete_ext2(path, ext) + def delete_ext2(path, *exts) p = get(path) - if has_ext?(p, ext) - p[0...p.rindex(ext)] - else - p - end + exts.each {|ext| + if has_ext?(p, ext) + return p[0...p.rindex(ext)] + end + } + + p end # Ensure the tail # # @example @@ -206,11 +207,11 @@ private end - DELEGATE_METHODS2 = [ :parent2 ] - DELEGATE_METHODS = [ :parent] + DELEGATE_METHODS2 = [ :parent2, :delete_ext2, :add_ext2 ] + DELEGATE_METHODS = [ :parent, :delete_ext, :add_ext] DELEGATE_METHODS2.each do |mth2| class_eval <<-EOF def #{mth2}(*args, &blk) Pa.#{mth2}(path, *args, &blk)