Class: Cbratools::String

Inherits:
Object
  • Object
show all
Defined in:
lib/cbratools/string.rb

Class Method Summary collapse

Class Method Details

.camelcase(string) ⇒ Object



11
12
13
14
# File 'lib/cbratools/string.rb', line 11

def self.camelcase(string)
  return string if string !~ /_/ && string =~ /[A-Z]+.*/
  string.split('_').map { |e| e.capitalize }.join
end

.underscore(string) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/cbratools/string.rb', line 3

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