class Newgistics::StringHelper
Constants
- CAMEL_CASED_STRING_REGEX
- CAPITALIZED_STRING_REGEX
- UNDERSCORED_STRING_REGEX
Public Class Methods
camelize(string, upcase_first: true)
click to toggle source
# File lib/newgistics/string_helper.rb, line 7 def self.camelize(string, upcase_first: true) string.to_s.dup.tap do |s| s.gsub!(UNDERSCORED_STRING_REGEX) { $1.capitalize! || $1 } s.gsub!(CAPITALIZED_STRING_REGEX) { $&.downcase! } unless upcase_first end end
underscore(string)
click to toggle source
# File lib/newgistics/string_helper.rb, line 14 def self.underscore(string) string.to_s.dup.tap do |s| s.gsub!(CAMEL_CASED_STRING_REGEX) { "#{$1}_#{$2}" } s.downcase! end end