class Rnfse::String
Public Class Methods
camelize(term, uppercase_first_letter = true)
click to toggle source
# File lib/rnfse/string.rb, line 4 def self.camelize(term, uppercase_first_letter = true) string = term.to_s if uppercase_first_letter string = string.sub(/^[a-z\d]*/) { $&.capitalize } else string = string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { $&.downcase } end string.gsub!(/(?:_|(\/))([a-z\d]*)/i) { $2.capitalize } string.gsub!('/', '::') self.new(string) end
demodulize(path)
click to toggle source
# File lib/rnfse/string.rb, line 35 def self.demodulize(path) path = path.to_s self.new( if i = path.rindex('::') path[(i+2)..-1] else path end ) end
underscore(term)
click to toggle source
# File lib/rnfse/string.rb, line 20 def self.underscore(term) word = term.to_s.gsub('::', '/') word.gsub!(/(?:([A-Za-z\d])|^)(?=\b|[^a-z])/) #{ "#{$1}#{$1 && '_'}#{$2.downcase}" } word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2') word.gsub!(/([a-z\d])([A-Z])/,'\1_\2') word.tr!("-", "_") word.downcase! self.new(word) end
Public Instance Methods
camelize()
click to toggle source
# File lib/rnfse/string.rb, line 16 def camelize self.class.camelize(self) end
demodulize()
click to toggle source
# File lib/rnfse/string.rb, line 44 def demodulize self.class.demodulize(self) end
underscore()
click to toggle source
# File lib/rnfse/string.rb, line 31 def underscore self.class.underscore(self) end