Module: Geokit::Inflector
Instance Method Summary collapse
- #camelize(str) ⇒ Object
- #humanize(lower_case_and_underscored_word) ⇒ Object
- #snake_case(s) ⇒ Object
- #titleize(word) ⇒ Object
- #underscore(camel_cased_word) ⇒ Object
- #url_escape(s) ⇒ Object
Instance Method Details
#camelize(str) ⇒ Object
52 53 54 |
# File 'lib/geokit/geocoders.rb', line 52 def camelize(str) str.split('_').map {|w| w.capitalize}.join end |
#humanize(lower_case_and_underscored_word) ⇒ Object
35 36 37 |
# File 'lib/geokit/geocoders.rb', line 35 def humanize(lower_case_and_underscored_word) lower_case_and_underscored_word.to_s.gsub(/_id$/, "").gsub(/_/, " ").capitalize end |
#snake_case(s) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/geokit/geocoders.rb', line 39 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 |
#titleize(word) ⇒ Object
23 24 25 |
# File 'lib/geokit/geocoders.rb', line 23 def titleize(word) humanize(underscore(word)).gsub(/\b([a-z])/u) { $1.capitalize } end |
#underscore(camel_cased_word) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/geokit/geocoders.rb', line 27 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 |
#url_escape(s) ⇒ Object
46 47 48 49 50 |
# File 'lib/geokit/geocoders.rb', line 46 def url_escape(s) s.gsub(/([^ a-zA-Z0-9_.-]+)/nu) do '%' + $1.unpack('H2' * $1.size).join('%').upcase end.tr(' ', '+') end |