Sha256: f3f258c6050c1418b14c176682579873352f59b99e800d65c3e58db6715a2c3a

Contents?: true

Size: 847 Bytes

Versions: 5

Compression:

Stored size: 847 Bytes

Contents

module Geokit
  module Inflector
    require 'cgi'

    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)
      CGI.escape(s)
    end

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
geokit-1.7.1 lib/geokit/inflectors.rb
geokit-1.7.0 lib/geokit/inflectors.rb
geokit-1.6.7 lib/geokit/inflectors.rb
geokit-1.6.6 lib/geokit/inflectors.rb
geokit-1.7.0.rc1 lib/geokit/inflectors.rb