Module: Generator::Utils
- Included in:
- API, Entrypoint, Operation, Path
- Defined in:
- lib/generator/utils.rb
Instance Method Summary collapse
Instance Method Details
#pascalcase(string, acronyms: ["FBA"]) ⇒ Object
15 16 17 18 19 |
# File 'lib/generator/utils.rb', line 15 def pascalcase(string, acronyms: ["FBA"]) s = string.split(/[_\s-]/).map(&:capitalize).join acronyms.each { |a| s.gsub!(/#{a.capitalize}/, a.upcase) } s end |
#snakecase(string) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/generator/utils.rb', line 7 def snakecase(string) string.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .gsub(/(\d{4})(\d{2})(\d{2})/, '_\1_\2_\3') # Format date-like sequences .tr("-", "_") .downcase end |