Sha256: 8407485d07abe479448405b05d730d820b4214f6a54427813cd24ce9275b11bb
Contents?: true
Size: 1.03 KB
Versions: 8
Compression:
Stored size: 1.03 KB
Contents
module RedboothRuby module Helpers # Transform a resource name into a class name. # Transform a Symbol|String: # capitalize the first letter # capitalize the first letter after _'s, removing the _'s # Example: camelize(:task_list) # => TaskList # Example: camelize('task_list') # => TaskList # # @param [Symbol|String] name to convert # @return [String] string of the class name def camelize(name) name.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } end # Transform a class name into a resource name. # Downcase all the letters, inserting an underscore _ before capitals # Example: underscore('TaskList') # => task_list # # @param [String] camel_case_word to convert # @return [String] string of the resource name def underscore(camel_case_word) camel_case_word.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end end end
Version data entries
8 entries across 8 versions & 1 rubygems