Module: Loqate::Util Private
- Defined in:
- lib/loqate/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
-
.camelize(term) ⇒ Object
private
Converts a string to camel case.
-
.underscore(term) ⇒ Object
private
Converts a string to snake case.
Class Method Details
.camelize(term) ⇒ Object
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
26 27 28 29 30 31 32 |
# File 'lib/loqate/util.rb', line 26 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) ⇒ Object
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
12 13 14 15 16 17 18 19 20 |
# File 'lib/loqate/util.rb', line 12 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 |