Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/chgk_rating/utils/snakecase.rb

Overview

Initial code taken from Facets gem by Rubyworks github.com/rubyworks/facets/blob/master/lib/core/facets/string/snakecase.rb

Instance Method Summary collapse

Instance Method Details

#snakecase_upcaseObject

Underscore a string such that camelcase, dashes and spaces are replaced by underscores.


7
8
9
10
11
12
13
14
15
# File 'lib/chgk_rating/utils/snakecase.rb', line 7

def snakecase_upcase
  split('::').last.
  gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
      gsub(/([a-z\d])([A-Z])/,'\1_\2').
      tr('-', '_').
      gsub(/\s/, '_').
      gsub(/__+/, '_').
      upcase
end