Sha256: 712706d4cd5205fbd3021016d2a71080e5a37f552752d236ab31c4ffac609f97

Contents?: true

Size: 489 Bytes

Versions: 58

Compression:

Stored size: 489 Bytes

Contents

# frozen_string_literal: true

module EacRubyUtils
  class Inflector
    class << self
      VARIABLE_NAME_PATTERN = /[_a-z][_a-z0-9]*/i.freeze

      def variableize(string)
        r = string.gsub(/[^_a-z0-9]/i, '_').gsub(/_+/, '_').gsub(/_\z/, '').gsub(/\A_/, '').downcase
        m = VARIABLE_NAME_PATTERN.match(r)
        return r if m

        raise ::ArgumentError, "Invalid variable name \"#{r}\" was generated " \
          "from string \"#{string}\""
      end
    end
  end
end

Version data entries

58 entries across 58 versions & 3 rubygems

Version Path
eac_ruby_utils-0.57.0 lib/eac_ruby_utils/inflector.rb
ehbrs-tools-0.17.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb
avm-tools-0.86.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb
avm-tools-0.85.1 vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb
eac_ruby_utils-0.56.2 lib/eac_ruby_utils/inflector.rb
avm-tools-0.85.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb
eac_ruby_utils-0.56.1 lib/eac_ruby_utils/inflector.rb
ehbrs-tools-0.16.5 vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb
avm-tools-0.84.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb
eac_ruby_utils-0.56.0 lib/eac_ruby_utils/inflector.rb
avm-tools-0.83.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb
ehbrs-tools-0.16.4 vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb
avm-tools-0.82.1 vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb
avm-tools-0.82.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb
avm-tools-0.81.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb
ehbrs-tools-0.16.3 vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb
eac_ruby_utils-0.55.0 lib/eac_ruby_utils/inflector.rb
avm-tools-0.80.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb
avm-tools-0.79.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb
avm-tools-0.78.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb