Module: WsdlMapper::Naming::Inflector
- Extended by:
- Inflector
- Defined in:
- lib/wsdl_mapper/naming/inflector.rb
Overview
Module with inflection helper methods. As a permanent dependency on Rails' ActiveSupport library is not feasible, here are some quick re-implementations.
Constant Summary collapse
- FIRST_CHAR =
/^./- NON_WORD =
/[^a-zA-Z]/- NON_AN =
/[^a-zA-Z0-9]/- NON_WORD_FOLLOWED_BY_WORD =
/[^a-zA-Z0-9]+([a-zA-Z0-9])/- CAPITALS =
/([A-Z])/- DOWN_FOLLOWED_BY_UP =
/([a-z0-9])([A-Z])/
Instance Method Summary collapse
-
#camelize(source) ⇒ String
Camelize a string.
-
#underscore(source) ⇒ String
Snake-cases a string.
Instance Method Details
#camelize(source) ⇒ String
Camelize a string.
20 21 22 23 24 25 |
# File 'lib/wsdl_mapper/naming/inflector.rb', line 20 def camelize(source) source. strip. gsub(NON_WORD_FOLLOWED_BY_WORD) { |_| $1.upcase }. sub(FIRST_CHAR) { |s| s.upcase } end |
#underscore(source) ⇒ String
Snake-cases a string.
32 33 34 35 36 37 38 39 |
# File 'lib/wsdl_mapper/naming/inflector.rb', line 32 def underscore(source) source. strip. gsub(DOWN_FOLLOWED_BY_UP) { |_| "#{$1}_#{$2.downcase}" }. downcase. gsub(NON_AN, '_'). gsub(/_+/, '_') end |