Sha256: c03fef323d19c6ca61bc2588558233fbc9e138904ab7ff245ec00aacec57b6e9
Contents?: true
Size: 824 Bytes
Versions: 3
Compression:
Stored size: 824 Bytes
Contents
module Loqate # Provides methods for string manipulation # # @api private module Util module_function # Converts a string to snake case # # @param [String|Symbol] term The term to be converted. # 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 # Converts a string to camel case # # @param [String|Symbol] term The term to be converted. # 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 end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
loqate-0.12.0 | lib/loqate/util.rb |
loqate-0.11.1 | lib/loqate/util.rb |
loqate-0.11.0 | lib/loqate/util.rb |