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



18
19
20
21
# File 'lib/jsx_rosetta/ast/inflector.rb', line 18

def camelize(string)
  parts = string.split("_")
  parts[0] + parts[1..].map(&:capitalize).join
end

.underscore(string) ⇒ Object



10
11
12
13
14
15
16
# 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')
    .tr("-", "_")
    .downcase
end