Sha256: 9179587b3ab62eb22bc0585ae9f99704f9f62c6878fae3f7db7da27865ae12c6

Contents?: true

Size: 875 Bytes

Versions: 12

Compression:

Stored size: 875 Bytes

Contents

class File
  def self.basename_wo_ext(s)
    bn = File.basename(s)
    if bn =~ /^(.*)\.([^.]*)$/
      $1
    else
      bn
    end
  end

  #
  # File.extname_wo_dot("x.y") => "y"
  # File.extname_wo_dot("x.") => ""
  # File.extname_wo_dot(".y") => ""
  # File.extname_wo_dot("x") => ""
  #
  def self.extname_wo_dot(s)
    File.extname(s) =~ /^\.([^.]*)$/ ? $1 : ""
  end
end

module File::Etest
  def test_extname_wo_dot
    assert_equal "y", File.extname_wo_dot("x.y")
    assert_equal "", File.extname_wo_dot("x.")
    assert_equal "", File.extname_wo_dot(".y")
    assert_equal "", File.extname_wo_dot("x")
  end

  def test_basename_wo_ext
    assert_equal "x", File.basename_wo_ext("x.y")
    assert_equal "x", File.basename_wo_ext("x.")
    assert_equal "", File.basename_wo_ext(".y")
    assert_equal "x", File.basename_wo_ext("x")
  end
end if VEX_TEST == "base"

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
vex-0.6.2 lib/vex/base/filesystem/parse_filename.rb
vex-0.4.4 lib/vex/base/filesystem/parse_filename.rb
vex-0.4.2 lib/vex/base/filesystem/parse_filename.rb
vex-0.3.3 lib/vex/base/filesystem/parse_filename.rb
vex-0.2.9 lib/vex/base/filesystem/parse_filename.rb
vex-0.2.8 lib/vex/base/filesystem/parse_filename.rb
vex-0.2.7 lib/vex/base/filesystem/parse_filename.rb
vex-0.2.6 lib/vex/base/filesystem/parse_filename.rb
vex-0.2.5 lib/vex/base/filesystem/parse_filename.rb
vex-0.2.2 lib/vex/base/filesystem/parse_filename.rb
vex-0.2.1 lib/vex/base/filesystem/parse_filename.rb
vex-0.2 lib/vex/base/filesystem/parse_filename.rb