Sha256: 31764551564041ba211a1d124e2ac696aad893ab7d8be82f37094929ebcf7fb4

Contents?: true

Size: 645 Bytes

Versions: 373

Compression:

Stored size: 645 Bytes

Contents

# frozen_string_literal: true

module EacRubyUtils
  module Fs
    class << self
      # A [File.extname] which find multiple extensions (Ex.: .tar.gz).
      def extname(path, limit = -1)
        recursive_extension(::File.basename(path), limit)
      end

      # Shortcut to +extname(2)+.
      def extname2(path)
        extname(path, 2)
      end

      private

      def recursive_extension(basename, limit)
        return '' if limit.zero?

        m = /\A(.+)(\.[a-z][a-z0-9]*)\z/i.match(basename)
        if m
          "#{recursive_extension(m[1], limit - 1)}#{m[2]}"
        else
          ''
        end
      end
    end
  end
end

Version data entries

373 entries across 373 versions & 4 rubygems

Version Path
eac_ruby_utils-0.124.0 lib/eac_ruby_utils/fs/extname.rb
eac_tools-0.97.2 sub/eac_ruby_utils/lib/eac_ruby_utils/fs/extname.rb
eac_ruby_utils-0.123.0 lib/eac_ruby_utils/fs/extname.rb
eac_ruby_utils-0.121.0 lib/eac_ruby_utils/fs/extname.rb
eac_ruby_utils-0.120.0 lib/eac_ruby_utils/fs/extname.rb
eac_tools-0.76.1 sub/eac_ruby_utils/lib/eac_ruby_utils/fs/extname.rb
eac_tools-0.76.0 sub/eac_ruby_utils/lib/eac_ruby_utils/fs/extname.rb
eac_tools-0.75.2 sub/eac_ruby_utils/lib/eac_ruby_utils/fs/extname.rb
eac_ruby_utils-0.119.2 lib/eac_ruby_utils/fs/extname.rb
eac_tools-0.75.1 sub/eac_ruby_utils/lib/eac_ruby_utils/fs/extname.rb
eac_tools-0.75.0 sub/eac_ruby_utils/lib/eac_ruby_utils/fs/extname.rb
eac_ruby_utils-0.119.1 lib/eac_ruby_utils/fs/extname.rb
eac_tools-0.74.1 sub/eac_ruby_utils/lib/eac_ruby_utils/fs/extname.rb
eac_tools-0.74.0 sub/eac_ruby_utils/lib/eac_ruby_utils/fs/extname.rb
eac_tools-0.73.0 sub/eac_ruby_utils/lib/eac_ruby_utils/fs/extname.rb
eac_ruby_utils-0.119.0 lib/eac_ruby_utils/fs/extname.rb
eac_tools-0.72.0 sub/eac_ruby_utils/lib/eac_ruby_utils/fs/extname.rb
eac_ruby_utils-0.118.1 lib/eac_ruby_utils/fs/extname.rb
eac_ruby_utils-0.118.0 lib/eac_ruby_utils/fs/extname.rb
eac_tools-0.70.1 sub/eac_ruby_utils/lib/eac_ruby_utils/fs/extname.rb