Module: ProtoPlugin::Utils
- Defined in:
- lib/proto_plugin/utils.rb
Overview
A set of utility functions used by the library.
Class Method Summary collapse
-
.camelize(value) ⇒ String
Converts string to UpperCamelCase.
Class Method Details
.camelize(value) ⇒ String
Converts string to UpperCamelCase.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/proto_plugin/utils.rb', line 12 def camelize(value) string = value.to_s if string.match?(/\A[a-z\d]*\z/) return string.capitalize else string = string.sub(/^[a-z\d]*/) do |match| match.capitalize! || match end end string.gsub!(%r{(?:_|(/))([a-z\d]*)}i) do word = ::Regexp.last_match(2) substituted = word.capitalize! || word ::Regexp.last_match(1) ? "::#{substituted}" : substituted end string end |