Module: Seahorse::Util Private

Defined in:
lib/seahorse/util.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Class Method Summary collapse

Class Method Details

.irregular_inflections(hash) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


8
9
10
11
# 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) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the underscored version of the given string.

Parameters:

  • string (String)

Returns:

  • (String)

    Returns the underscored version of the given string.


15
16
17
18
19
20
21
22
# File 'lib/seahorse/util.rb', line 15

def underscore(string)
  new_string = string.dup
  new_string.gsub!(@irregular_regex) { |word| "_#{@irregular_inflections[word]}" }
  new_string.gsub!(/([A-Z0-9]+)([A-Z][a-z])/, '\1_\2'.freeze)
  new_string = new_string.scan(/[a-z0-9]+|\d+|[A-Z0-9]+[a-z]*/).join('_'.freeze)
  new_string.downcase!
  new_string
end

.uri_escape(string) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


24
25
26
# File 'lib/seahorse/util.rb', line 24

def uri_escape(string)
  CGI.escape(string.encode('UTF-8')).gsub('+', '%20').gsub('%7E', '~')
end

.uri_path_escape(path) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


28
29
30
# File 'lib/seahorse/util.rb', line 28

def uri_path_escape(path)
  path.gsub(/[^\/]+/) { |part| uri_escape(part) }
end