Class: String
Instance Method Summary collapse
- #camelcase ⇒ Object
- #classify ⇒ Object
- #lower_camelcase ⇒ Object
- #snakecase ⇒ Object
- #tableify ⇒ Object
Instance Method Details
#camelcase ⇒ Object
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 |
#classify ⇒ Object
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_camelcase ⇒ Object
17 18 19 |
# File 'lib/helper_utils.rb', line 17 def lower_camelcase self[0].chr.downcase + self.camelcase[1..-1] end |
#snakecase ⇒ Object
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 |
#tableify ⇒ Object
27 28 29 |
# File 'lib/helper_utils.rb', line 27 def tableify self.snakecase + 's' end |