Class: Relocator::Support::Underscore
- Inherits:
-
Object
- Object
- Relocator::Support::Underscore
- Defined in:
- lib/relocator/support/underscore.rb
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(string) ⇒ Underscore
constructor
A new instance of Underscore.
Constructor Details
#initialize(string) ⇒ Underscore
Returns a new instance of Underscore.
6 7 8 |
# File 'lib/relocator/support/underscore.rb', line 6 def initialize(string) self.string = string.to_s end |
Class Method Details
.call(*args) ⇒ Object
2 3 4 |
# File 'lib/relocator/support/underscore.rb', line 2 def self.call(*args) new(*args).call end |
Instance Method Details
#call ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/relocator/support/underscore.rb', line 10 def call return string unless /[A-Z-]|::/.match?(string) string .gsub("::".freeze, "/".freeze) .gsub(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2'.freeze) .gsub(/([a-z\d])([A-Z])/, '\1_\2'.freeze) .tr("-".freeze, "_".freeze) .downcase end |