Class: HealthyRack::Utils::String

Inherits:
Object
  • Object
show all
Defined in:
lib/healthy_rack/utils.rb

Overview

Constant Summary collapse

NAMESPACE_SEPARATOR =
'::'.freeze
UNDERSCORE_SEPARATOR =
'/'.freeze
UNDERSCORE_DIVISION_TARGET =
'\1_\2'.freeze

Class Method Summary collapse

Class Method Details

.demodulize(input) ⇒ Object



9
10
11
# File 'lib/healthy_rack/utils.rb', line 9

def self.demodulize(input)
  ::String.new(input.to_s).split(NAMESPACE_SEPARATOR).last
end

.underscore(input) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/healthy_rack/utils.rb', line 13

def self.underscore(input)
  string = ::String.new(input.to_s)
  string.gsub!(NAMESPACE_SEPARATOR, UNDERSCORE_SEPARATOR)
  string.gsub!(NAMESPACE_SEPARATOR, UNDERSCORE_SEPARATOR)
  string.gsub!(/([A-Z\d]+)([A-Z][a-z])/, UNDERSCORE_DIVISION_TARGET)
  string.gsub!(/([a-z\d])([A-Z])/, UNDERSCORE_DIVISION_TARGET)
  string.gsub!(/[[:space:]]|\-/, UNDERSCORE_DIVISION_TARGET)
  string.downcase
end