Module: WowzaRest::CoreExt::String::Inflections
- Defined in:
- lib/wowza_rest/core_ext/string/inflections.rb
Instance Method Summary collapse
- #camelize ⇒ Object
-
#underscore ⇒ Object
its mainly used when converting json attrs to getters/setters methods wowza rest api responses sometimes have attributes that contains dots and this causes problems when trying to convert it to a method thats why i have to replace all dots with underscores.
Instance Method Details
#camelize ⇒ Object
18 19 20 21 22 23 |
# File 'lib/wowza_rest/core_ext/string/inflections.rb', line 18 def camelize tr('-', '_') .gsub(/\b[A-Z]+/, &:downcase) .gsub(/_(.)/, &:upcase) .tr('_', '') end |
#underscore ⇒ Object
its mainly used when converting json attrs to getters/setters methods wowza rest api responses sometimes have attributes that contains dots and this causes problems when trying to convert it to a method thats why i have to replace all dots with underscores
9 10 11 12 13 14 15 16 |
# File 'lib/wowza_rest/core_ext/string/inflections.rb', line 9 def underscore gsub(/::/, '/') .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .tr('-', '_') .tr('.', '_') .downcase end |