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
avm-tools-0.72.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb
eac_ruby_utils-0.47.0 lib/eac_ruby_utils/inflector.rb
avm-tools-0.71.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb
avm-tools-0.70.2 vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb
ehbrs-tools-0.15.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb
ehbrs-tools-0.14.1 vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb
avm-tools-0.70.1 vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb
avm-tools-0.70.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb
avm-tools-0.69.3 vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb
ehbrs-tools-0.14.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb
avm-tools-0.69.2 vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb
avm-tools-0.69.1 vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb
eac_ruby_utils-0.46.0 lib/eac_ruby_utils/inflector.rb
avm-tools-0.69.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb
eac_ruby_utils-0.45.2 lib/eac_ruby_utils/inflector.rb
eac_ruby_utils-0.45.1 lib/eac_ruby_utils/inflector.rb
eac_ruby_utils-0.45.0 lib/eac_ruby_utils/inflector.rb
ehbrs-tools-0.13.1 vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb