Module: Polyn::Utils::String

Defined in:
lib/polyn/utils/string.rb

Overview

Utilities for working with strings.

Class Method Summary collapse

Class Method Details

.to_camel_case(str) ⇒ String

Converts a string to camel case.

Parameters:

  • str

    ing [String] The string to convert.

Returns:

  • (String)

    The camel cased string.



31
32
33
34
35
# File 'lib/polyn/utils/string.rb', line 31

def self.to_camel_case(str)
  str    = str.to_s.split("_").map(&:capitalize).join
  str[0] = str[0].downcase
  str
end

.to_class_name(str) ⇒ Object



44
45
46
# File 'lib/polyn/utils/string.rb', line 44

def self.to_class_name(str)
  str.split("_").map(&:capitalize).join
end

.to_snake_case(str) ⇒ Object



37
38
39
40
41
42
# File 'lib/polyn/utils/string.rb', line 37

def self.to_snake_case(str)
  str.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
     .gsub(/([a-z\d])([A-Z])/, '\1_\2')
     .tr("-", "_")
     .downcase
end