Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/ziya/core_ext/string.rb

Overview


Various text utils. Yes indeed lifted from Inflector.

Author

Fernand Galiana

Date

Dec 15th, 2006


Instance Method Summary collapse

Instance Method Details

#camelize_itObject

Pulled from the Rails Inflector class and modified slightly to fit our needs.



9
10
11
# File 'lib/ziya/core_ext/string.rb', line 9

def camelize_it()
  self.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
end

#classifyObject

Pulled from the Rails Inflector class and modified slightly to fit our needs.



23
24
25
# File 'lib/ziya/core_ext/string.rb', line 23

def classify
  self.sub(/.*\./, '').camelize_it
end

#demodulizeObject

strip out module name and return bare class name



28
29
30
# File 'lib/ziya/core_ext/string.rb', line 28

def demodulize
  self.gsub( /^.*::/, '' )
end

#underscoreObject

Same as Rails Inflector but eliminating inflector dependency



14
15
16
17
18
19
20
# File 'lib/ziya/core_ext/string.rb', line 14

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