module Tide::API::Util
Provides methods for string manipulation
@api private
Public Instance Methods
camelize(term)
click to toggle source
Converts a string to camel case
@param [String|Symbol] term The term to be converted.
@return [String] A camel-cased version of the input
# File lib/tide/api/util.rb, line 32 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)
click to toggle source
Converts a string to snake case
@param [String|Symbol] term The term to be converted.
@return [String] A snake-cased version of the input
# File lib/tide/api/util.rb, line 16 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