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



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

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

#humanizeObject



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

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

#titleizeObject



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

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

#underscoreObject



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

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