Sha256: a40bbb2e062ffa51296532f2dbb4df33a5631f85aa1ef3ffade90931ba738e56
Contents?: true
Size: 1.35 KB
Versions: 32
Compression:
Stored size: 1.35 KB
Contents
module Toolhound module Util # class << self def acronyms {"rest" => "REST", "html" =>"HTML", "id" => "ID", "url" => "URL"} end def acronym_regex /#{acronyms.values.join("|")}/ end def demodulize(path) path = path.to_s if i = path.rindex('::') path[(i+2)..-1] else path end end def underscore(camel_cased_word) return camel_cased_word unless camel_cased_word =~ /[A-Z-]|::/ word = camel_cased_word.to_s.gsub('::'.freeze, '/'.freeze) word.gsub!(/(?:(?<=([A-Za-z\d]))|\b)(#{acronym_regex})(?=\b|[^a-z])/) { "#{$1 && '_'.freeze }#{$2.downcase}" } word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2'.freeze) word.gsub!(/([a-z\d])([A-Z])/, '\1_\2'.freeze) word.tr!("-".freeze, "_".freeze) word.downcase! word end def camelize(term, uppercase_first_letter = true) string = term.to_s if uppercase_first_letter string = string.sub(/^[a-z\d]*/) { |match| match.capitalize } else string = string.sub(/^(?:#{acronym_regex}(?=\b|[A-Z_])|\w)/) { |match| match.downcase } end string.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{acronyms[$2] || $2.capitalize}" } string.gsub!('/'.freeze, '::'.freeze) string end # end end end
Version data entries
32 entries across 32 versions & 1 rubygems