Sha256: 5be1f5037a01f9780b1d4de998589ae2c4e0140a5c58995490be308cfd71e088
Contents?: true
Size: 866 Bytes
Versions: 4
Compression:
Stored size: 866 Bytes
Contents
module Lita # Handy utilities used by other 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 "#{Regexp.last_match[1]}#{Regexp.last_match[1] && '_'}#{Regexp.last_match[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
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
lita-3.0.3 | lib/lita/util.rb |
lita-3.0.2 | lib/lita/util.rb |
lita-3.0.1 | lib/lita/util.rb |
lita-3.0.0 | lib/lita/util.rb |