module Seahorse::Util

@api private

Public Class Methods

irregular_inflections(hash) click to toggle source
# File lib/seahorse/util.rb, line 8
def irregular_inflections(hash)
  @irregular_inflections.update(hash)
  @irregular_regex = Regexp.new(@irregular_inflections.keys.join('|'))
end
underscore(string) click to toggle source

@param [String] string @return [String] Returns the underscored version of the given string.

# File lib/seahorse/util.rb, line 15
def underscore(string)
  string.
    gsub(@irregular_regex) { |word| '_' + @irregular_inflections[word] }.
    gsub(/([A-Z0-9]+)([A-Z][a-z])/, '\1_\2').
    scan(/[a-z0-9]+|\d+|[A-Z0-9]+[a-z]*/).
    join('_').downcase
end
uri_escape(string) click to toggle source
# File lib/seahorse/util.rb, line 23
def uri_escape(string)
  CGI.escape(string.encode('UTF-8')).gsub('+', '%20').gsub('%7E', '~')
end