Class: ReeString::Camelize

Inherits:
Object
  • Object
show all
Includes:
Ree::FnDSL
Defined in:
lib/ree_lib/packages/ree_string/package/ree_string/functions/camelize.rb

Instance Method Summary collapse

Instance Method Details

#call(str, **opts) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ree_lib/packages/ree_string/package/ree_string/functions/camelize.rb', line 35

def call(str, **opts)
  str = str.dup
  uppercase_first_letter = opts.has_key?(:uppercase_first_letter) ? opts[:uppercase_first_letter] : true
  acronyms = opts[:acronyms] || {}
  regex = acronyms_camelize_regex(acronyms.values)

  if !uppercase_first_letter
    str = str.sub(regex) { |match| match.downcase! || match }
  else
    str = str.sub(/^[a-z\d]*/) { |match| acronyms[match] || match.capitalize! || match }
  end

  str.gsub!(/(?:_|(\/))([a-z\d]*)/i) do
    word = $2
    substituted = acronyms[word] || word.capitalize! || word
    $1 ? "::#{substituted}" : substituted
  end

  str
end