Class: CamelString

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ruby-processing/helpers/camel_string.rb

Overview

Avoid the monkey patching of String for camelize

Instance Method Summary collapse

Constructor Details

#initialize(str = 'no_name') ⇒ CamelString

Returns a new instance of CamelString.



7
8
9
# File 'lib/ruby-processing/helpers/camel_string.rb', line 7

def initialize(str = 'no_name')
  @string = (str.length > 60) ? 'long_name' : str
end

Instance Method Details

#camelize(first_letter_in_uppercase = true) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/ruby-processing/helpers/camel_string.rb', line 11

def camelize(first_letter_in_uppercase = true)
  if first_letter_in_uppercase
    @string.gsub(%r{\/(.?)}) { '::' + Regexp.last_match[1].upcase }
      .gsub(/(^|_)(.)/) { Regexp.last_match[2].upcase }
  else
    @string[0] + camelize[1..-1]
  end
end