Sha256: 114bdac446c2315c3cf57e2bef8330501d47b91bfbf9e6e3158ad48b8dc0af2e

Contents?: true

Size: 1000 Bytes

Versions: 23

Compression:

Stored size: 1000 Bytes

Contents

class String

  # Converts a string into a unix path.
  # This method is geared toward code reflection.
  #
  # See : String#modulize, String#methodize
  #
  #   "MyModule::MyClass".pathize   #=> my_module/my_class
  #   "my_module__my_class".pathize #=> my_module/my_class
  #
  # TODO :
  #
  # * Make sure that all scenarios return a valid unix path
  # * Make sure it is revertible
  #
  def pathize
    to_s.gsub(/([A-Z])/, '_\1').downcase.gsub(/^_/,'').gsub(/(::|__)_?/, '/')
  end

end


#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
=begin test

  require 'test/unit'

  class TCString < Test::Unit::TestCase

    def test_pathize
      assert_equal( 'my_module/my_class',   'MyModule::MyClass'.pathize )
      assert_equal( 'u_r_i',                'URI'.pathize )
      assert_equal( '/my_class',            '::MyClass'.pathize )
      assert_equal( '/my_module/my_class/', '/my_module/my_class/'.pathize )
    end

  end

=end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
facets-1.2.0 lib/facets/core/string/pathize.rb
facets-1.3.0 lib/facets/core/string/pathize.rb
facets-1.2.1 lib/facets/core/string/pathize.rb
facets-1.1.0 lib/facet/string/pathize.rb
facets-1.3.3 lib/facets/core/string/pathize.rb
facets-1.3.1 lib/facets/core/string/pathize.rb
facets-1.3.2 lib/facets/core/string/pathize.rb
facets-1.4.1 lib/facets/core/string/pathize.rb
facets-1.4.0 lib/facets/core/string/pathize.rb
facets-1.4.2 lib/facets/core/string/pathize.rb
facets-1.4.3 lib/facets/core/string/pathize.rb
facets-1.4.5 lib/facets/core/string/pathize.rb
facets-1.4.4 lib/facets/core/string/pathize.rb
facets-1.7.0 lib/facets/core/string/pathize.rb
facets-1.7.38 lib/facets/core/string/pathize.rb
facets-1.7.30 lib/facets/core/string/pathize.rb
facets-1.7.46 lib/facets/core/string/pathize.rb
facets-1.8.0 lib/facets/core/string/pathize.rb
facets-1.8.20 lib/facets/core/string/pathize.rb
facets-1.8.49 lib/facets/core/string/pathize.rb