module WsdlMapper::Naming::Inflector
Module with inflection helper methods. As a permanent dependency on Rails' ActiveSupport library is not feasible, here are some quick re-implementations.
Constants
- CAPITALS
- DOWN_FOLLOWED_BY_UP
- FIRST_CHAR
- NON_AN
- NON_WORD
- NON_WORD_FOLLOWED_BY_WORD
Public Instance Methods
camelize(source)
click to toggle source
Camelize a string. @param [String] source String to camelize. @return [String] Camelized string. @example
camelize('foo_bar baz ') #=> 'FooBarBaz'
# 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)
click to toggle source
Snake-cases a string. @param [String] source String to underscore. @return [String] snake-cased string. @example
underscore('Foo Bar') #=> 'foo_bar'
# 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