Class: String

Inherits:
Object show all
Defined in:
lib/helper_utils.rb

Instance Method Summary collapse

Instance Method Details

#camelcaseObject



12
13
14
15
# File 'lib/helper_utils.rb', line 12

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

#classifyObject



21
22
23
24
25
# File 'lib/helper_utils.rb', line 21

def classify
  self.split('/').collect do |c|
    c.camelcase
  end.join('::')
end

#lower_camelcaseObject



17
18
19
# File 'lib/helper_utils.rb', line 17

def lower_camelcase
  self[0].chr.downcase + self.camelcase[1..-1]
end

#snakecaseObject



2
3
4
5
6
7
8
9
10
# File 'lib/helper_utils.rb', line 2

def snakecase
  self.gsub(/::/, '/'). # Convert namespace to slash
  gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
  gsub(/([a-z\d])([A-Z])/,'\1_\2').
  tr('-', '_').
  gsub(/\s/, '_').
  gsub(/__+/, '_').
  downcase
end

#tableifyObject



27
28
29
# File 'lib/helper_utils.rb', line 27

def tableify
  self.snakecase + 's'
end