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

#ziya_camelizeObject

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 ziya_camelize()
  self.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
end

#ziya_classifyObject

Gen a class



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

def ziya_classify
  self.sub(/.*\./, '').ziya_camelize
end

#ziya_demodulizeObject

strip out module name and return bare class name



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

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

#ziya_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 ziya_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