Sha256: ed25e9f117269a6a73cfdd292ec9e3b48c5e40b4beefbac210e6b2601b944df5
Contents?: true
Size: 950 Bytes
Versions: 3
Compression:
Stored size: 950 Bytes
Contents
module Geokit module Inflector extend self def titleize(word) humanize(underscore(word)).gsub(/\b([a-z])/u) { $1.capitalize } end def underscore(camel_cased_word) camel_cased_word.to_s.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/u,'\1_\2'). gsub(/([a-z\d])([A-Z])/u,'\1_\2'). tr("-", "_"). downcase end def humanize(lower_case_and_underscored_word) lower_case_and_underscored_word.to_s.gsub(/_id$/, "").gsub(/_/, " ").capitalize end def snake_case(s) return s.downcase if s =~ /^[A-Z]+$/u s.gsub(/([A-Z]+)(?=[A-Z][a-z]?)|\B[A-Z]/u, '_\&') =~ /_*(.*)/ return $+.downcase end def url_escape(s) s.gsub(/([^ a-zA-Z0-9_.-]+)/nu) do '%' + $1.unpack('H2' * $1.size).join('%').upcase end.tr(' ', '+') end def camelize(str) str.split('_').map {|w| w.capitalize}.join end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
sayso-geokit-1.5.0.3.003 | lib/geokit/inflector.rb |
sayso-geokit-1.5.0.3.002 | lib/geokit/inflector.rb |
sayso-geokit-1.5.0.3.001 | lib/geokit/inflector.rb |