class Drillbit::Utilities::String
Constants
- SINGULARIZATION_RULES
rubocop:disable Metrics/LineLength
Public Class Methods
singularize(word)
click to toggle source
# File lib/drillbit/utilities/string.rb, line 51 def self.singularize(word) result = word.to_s.dup SINGULARIZATION_RULES.each do |(rule, replacement)| break if result.sub!(rule, replacement) end result end
underscore(other)
click to toggle source
rubocop:enable Metrics/LineLength
# File lib/drillbit/utilities/string.rb, line 39 def self.underscore(other) word = other.to_s.gsub('::', '/') word.gsub!(/(?:([A-Za-z\d])|^)(?=\b|[^a-z])/) do "#{Regexp.last_match(1)}#{Regexp.last_match(1) && ''}" end word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2') word.gsub!(/([a-z\d])([A-Z])/, '\1_\2') word.tr!('-', '_') word.downcase! word end