Module: JsxRosetta::AST::Inflector
- Defined in:
- lib/jsx_rosetta/ast/inflector.rb
Overview
Internal helpers for converting between Babel’s camelCase field names and Ruby’s snake_case conventions.
Class Method Summary collapse
Class Method Details
.camelize(string) ⇒ Object
17 18 19 20 |
# File 'lib/jsx_rosetta/ast/inflector.rb', line 17 def camelize(string) parts = string.split("_") parts[0] + parts[1..].map(&:capitalize).join end |
.underscore(string) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/jsx_rosetta/ast/inflector.rb', line 10 def underscore(string) string .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .downcase end |