Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-processing/helpers/string.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#camelize(first_letter_in_uppercase = true) ⇒ Object



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

def camelize(first_letter_in_uppercase = true)
  if first_letter_in_uppercase
    self.gsub(/\/(.?)/) { '::' + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
  else
    self.first + self.camelize[1..-1]
  end
end

#humanizeObject



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

def humanize()
  self.gsub(/_id$/, '').gsub(/_/, ' ').capitalize
end

#titleizeObject



3
4
5
# File 'lib/ruby-processing/helpers/string.rb', line 3

def titleize
  self.underscore.humanize.gsub(/\b([a-z])/) { $1.capitalize }
end

#underscoreObject



19
20
21
22
23
24
25
# File 'lib/ruby-processing/helpers/string.rb', line 19

def underscore
  self.gsub(/::/, '/')
    .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
    .gsub(/([a-z\d])([A-Z])/, '\1_\2')
    .tr('-', '_')
    .downcase
end