Module: StringNamefyExtension

Defined in:
lib/arfy/string_extensions.rb

Instance Method Summary collapse

Instance Method Details

#camelize(first_letter_in_uppercase = :upper) ⇒ Object



8
9
10
11
12
13
# File 'lib/arfy/string_extensions.rb', line 8

def camelize(first_letter_in_uppercase =:upper)
  s = gsub(/\/(.?)/){|x| "::#{x[-1..-1].upcase unless x == '/'}"}.
    gsub(/(^|_)(.)/){|x| x[-1..-1].upcase}
  s[0...1] = s[0...1].downcase unless first_letter_in_uppercase == :upper
  s
end

#classifyObject



15
16
17
18
19
# File 'lib/arfy/string_extensions.rb', line 15

def classify
  str = sub(/.*\./, '').tr("-", "")
  class << str; include StringNamefyExtension; end
  str.camelize
end

#underscoreObject



3
4
5
6
# File 'lib/arfy/string_extensions.rb', line 3

def underscore
  gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
    gsub(/([a-z\d])([A-Z])/,'\1_\2').tr("-", "_").downcase
end