Module: Tide::API::Util Private

Defined in:
lib/tide/api/util.rb

Overview

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.

Provides methods for string manipulation

Class Method Summary collapse

Class Method Details

.camelize(term) ⇒ 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.

Converts a string to camel case

Parameters:

  • term (String|Symbol)

    The term to be converted.

Returns:

  • (String)

    A camel-cased version of the input



32
33
34
35
36
37
38
# File 'lib/tide/api/util.rb', line 32

def camelize(term)
  string = term.to_s
  string = string.sub(/^[a-z\d]*/, &:capitalize)
  string.gsub!(%r{(?:_|(\/))([a-z\d]*)}) { "#{Regexp.last_match(1)}#{Regexp.last_match(2).capitalize}" }
  string.gsub!('/'.freeze, '::'.freeze)
  string
end

.underscore(term) ⇒ 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.

Converts a string to snake case

Parameters:

  • term (String|Symbol)

    The term to be converted.

Returns:

  • (String)

    A snake-cased version of the input



16
17
18
19
20
21
22
23
24
# File 'lib/tide/api/util.rb', line 16

def underscore(term)
  term
    .to_s
    .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
    .gsub(/([a-z\d])([A-Z])/, '\1_\2')
    .tr('-', '_')
    .downcase
    .to_sym
end