Module: Geokit::Inflector

Extended by:
Inflector
Included in:
Inflector
Defined in:
lib/geokit/inflectors.rb

Instance Method Summary collapse

Instance Method Details

#camelize(str) ⇒ Object



34
35
36
# File 'lib/geokit/inflectors.rb', line 34

def camelize(str)
  str.split('_').map {|w| w.capitalize}.join
end

#humanize(lower_case_and_underscored_word) ⇒ Object



19
20
21
# File 'lib/geokit/inflectors.rb', line 19

def humanize(lower_case_and_underscored_word)
  lower_case_and_underscored_word.to_s.gsub(/_id$/, "").gsub(/_/, " ").capitalize
end

#snake_case(s) ⇒ Object



23
24
25
26
27
28
# File 'lib/geokit/inflectors.rb', line 23

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



7
8
9
# File 'lib/geokit/inflectors.rb', line 7

def titleize(word)
  humanize(underscore(word)).gsub(/\b([a-z])/u) { $1.capitalize }
end

#underscore(camel_cased_word) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/geokit/inflectors.rb', line 11

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



30
31
32
# File 'lib/geokit/inflectors.rb', line 30

def url_escape(s)
  CGI.escape(s)
end