Module: Mortymer::Utils::StringTransformations

Included in:
OpenapiGenerator
Defined in:
lib/mortymer/utils/string_transformations.rb

Overview

Provides string transformation utilities similar to ActiveSupport’s methods

Class Method Summary collapse

Class Method Details

.demodulize(path) ⇒ Object



21
22
23
24
25
# File 'lib/mortymer/utils/string_transformations.rb', line 21

def demodulize(path)
  return path unless path.is_a?(String)

  path.split("::").last
end

.underscore(camel_cased_word) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/mortymer/utils/string_transformations.rb', line 9

def underscore(camel_cased_word)
  return camel_cased_word unless camel_cased_word.is_a?(String)

  word = camel_cased_word.to_s.dup
  word.gsub!(/::/, "/")
  word.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
  word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
  word.tr!("-", "_")
  word.downcase!
  word
end