Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/office365/utils/string.rb
Instance Method Summary collapse
-
#rails_camelize(uppercase_first_letter: false) ⇒ Object
rubocop:disable Style/SymbolProc.
- #rails_underscore ⇒ Object
Instance Method Details
#rails_camelize(uppercase_first_letter: false) ⇒ Object
rubocop:disable Style/SymbolProc
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/office365/utils/string.rb', line 15 def rails_camelize(uppercase_first_letter: false) string = self return string if string !~ /_/ && string =~ /[A-Z]+.*/ string = if uppercase_first_letter string.sub(/^[a-z\d]*/) { |match| match.capitalize } else string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { |match| match.downcase } end string.gsub(%r{(?:_|(/))([a-z\d]*)}) { "#{::Regexp.last_match(1)}#{::Regexp.last_match(2).capitalize}" }.gsub("/", "::") end |
#rails_underscore ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/office365/utils/string.rb', line 4 def rails_underscore gsub(/::/, "/") .gsub(/@/, "") .gsub(/\./, "_") .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .tr("-", "_") .downcase end |