Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/open_api_import/utils.rb
Instance Method Summary collapse
-
#camel_case ⇒ void
Convert to CamelCase a string.
-
#snake_case ⇒ void
Convert to snake_case a string.
Instance Method Details
#camel_case ⇒ void
Convert to CamelCase a string
16 17 18 19 20 21 |
# File 'lib/open_api_import/utils.rb', line 16 def camel_case return self if self !~ /_/ && self !~ /-/ && self !~ /\s/ && self =~ /^[A-Z]+.*/ gsub(/\W/, '_') .split('_').map(&:capitalize).join end |
#snake_case ⇒ void
Convert to snake_case a string
5 6 7 8 9 10 11 |
# File 'lib/open_api_import/utils.rb', line 5 def snake_case gsub(/\W/, '_') .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z])([A-Z])/, '\1_\2') .downcase .gsub(/_+/, '_') end |