Sha256: aca67f4f11a035adc055205d3090de144fe22cbb495effd72ce0c4e76898ff62

Contents?: true

Size: 816 Bytes

Versions: 13

Compression:

Stored size: 816 Bytes

Contents

module Lita
  # Handy utilities used by other parts Lita classes.
  module Util
    # A regular expression for acronyms.
    ACRONYM_REGEX = /(?=a)b/

    class << self
      # Transforms a camel-cased string into a snaked-cased string. Taken from
      # +ActiveSupport.+
      # @param camel_cased_word [String] The word to transform.
      # @return [String] The transformed word.
      def underscore(camel_cased_word)
        word = camel_cased_word.to_s.dup
        word.gsub!('::', '/')
        word.gsub!(/(?:([A-Za-z\d])|^)(#{ACRONYM_REGEX})(?=\b|[^a-z])/) do
          "#{$1}#{$1 && '_'}#{$2.downcase}"
        end
        word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
        word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
        word.tr!("-", "_")
        word.downcase!
        word
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
lita-2.7.2 lib/lita/util.rb
lita-2.7.1 lib/lita/util.rb
lita-2.7.0 lib/lita/util.rb
lita-2.6.0 lib/lita/util.rb
lita-2.5.0 lib/lita/util.rb
lita-2.4.0 lib/lita/util.rb
lita-2.3.0 lib/lita/util.rb
lita-2.2.1 lib/lita/util.rb
lita-2.2.0 lib/lita/util.rb
lita-2.1.2 lib/lita/util.rb
lita-2.1.1 lib/lita/util.rb
lita-2.1.0 lib/lita/util.rb
lita-2.0.0 lib/lita/util.rb