Sha256: cdf914620a46d0934b275562514e0898c316efe54175487ec34d2b0b5790baf3

Contents?: true

Size: 644 Bytes

Versions: 2

Compression:

Stored size: 644 Bytes

Contents

# frozen_string_literal: true

module FastUnderscore
  # Uses ActiveSupport's `acronym_underscore_regex` method for replacing
  # acronyms within strings that need to be underscored.
  module AcronymUnderscoreRegex
    def underscore(string)
      return string unless /[A-Z-]|::/.match?(string)

      response = string.dup
      acronyms = ActiveSupport::Inflector.inflections.acronyms_underscore_regex

      response.gsub!(acronyms) { "#{$1 && '_'}#{$2.downcase}" }

      FastUnderscore.underscore(response)
    end
  end

  class << ActiveSupport::Inflector
    alias as_underscore underscore
    include AcronymUnderscoreRegex
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fast_underscore-0.3.1 lib/fast_underscore/acronym_underscore_regex.rb
fast_underscore-0.3.0 lib/fast_underscore/acronym_underscore_regex.rb