Sha256: 10a78084c4eb00566fb23ea8fd1e3ed4eea31d9f20033a5bd8c76bf9d8f27254

Contents?: true

Size: 886 Bytes

Versions: 3

Compression:

Stored size: 886 Bytes

Contents

module Assertion

  # The collection of pure functions for converting constants
  # to corresponding path names.
  #
  # @api private
  #
  # @todo Extract this module to the external gem `transproc-inflector`
  #
  module Inflector

    extend ::Transproc::Registry

    # @private
    def to_snake(name)
      name.gsub(/([a-z])([A-Z])/, '\1_\2').gsub(/_+/, "_").downcase
    end

    # @private
    def to_path(name)
      name.split(%r{\:\:|-|/}).reject(&:empty?).join("/")
    end

    # Converts the name of the constant to the corresponding path
    #
    # @example
    #   fn = Inflector[:to_snake_path]
    #   fn["::Foo::BarBaz"]
    #   # => "foo/bar_baz"
    #
    # @param [String] name The name of the constant
    #
    # @return [String] The path
    #
    def to_snake_path(name)
      to_path(to_snake(name))
    end

  end # module Inflector

end # module Assertion

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
assertion-0.2.1 lib/assertion/inflector.rb
assertion-0.2.0 lib/assertion/inflector.rb
assertion-0.1.0 lib/assertion/transprocs/inflector.rb