lib/ruby_lokalise_api/utils/strings.rb in ruby-lokalise-api-9.0.1 vs lib/ruby_lokalise_api/utils/strings.rb in ruby-lokalise-api-9.2.0

- old
+ new

@@ -2,18 +2,19 @@ module RubyLokaliseApi module Utils module Strings refine String do - # Initial code taken from Facets gem by Rubyworks + # Converts a string to snake_case format. + # Original code inspired by the Facets gem by Rubyworks: # https://github.com/rubyworks/facets/blob/master/lib/core/facets/string/snakecase.rb def snakecase - gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2'). - gsub(/([a-z\d])([A-Z])/, '\1_\2'). - tr('-', '_'). - gsub(/\s/, '_'). - gsub(/__+/, '_'). - downcase + gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2'). # Handle acronyms like 'HTMLParser' + gsub(/([a-z\d])([A-Z])/, '\1_\2'). # Handle camelCase to snake_case + tr('-', '_'). # Replace dashes with underscores + gsub(/\s/, '_'). # Replace spaces with underscores + gsub(/__+/, '_'). # Collapse multiple underscores + downcase # Convert everything to lowercase end end end end end