Module: Treat::Helpers::String::UnCamelCaseable
- Defined in:
- lib/treat/helpers/string.rb
Overview
Counterpart of Treat::Helpers::CamelCaseable; transforms a CamelCase string to its un_camel_ case corresponding form.
Constant Summary collapse
- @@ucc_cache =
A cache to optimize un camel casing.
{}
Instance Method Summary collapse
-
#un_camel_case ⇒ Object
(also: #ucc)
Convert CamelCase to un_camel_case.
Instance Method Details
#un_camel_case ⇒ Object Also known as: ucc
Convert CamelCase to un_camel_case.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/treat/helpers/string.rb', line 79 def un_camel_case o_phrase, phrase = to_s, to_s.dup if @@ucc_cache[o_phrase] return @@ucc_cache[o_phrase] end acros = Treat.core.acronyms if !acros.include?(phrase.downcase) phrase.gsub!(/[A-Z]/) do |p| '_' + p.downcase end if phrase[0] == '_' return phrase = phrase[1..-1] end else phrase = phrase.downcase end @@ucc_cache[o_phrase] = phrase end |