Module: RedboothRuby::Helpers
- Defined in:
- lib/redbooth-ruby/helpers.rb
Instance Method Summary collapse
-
#camelize(name) ⇒ String
Transform a resource name into a class name.
-
#underscore(camel_case_word) ⇒ String
Transform a class name into a resource name.
Instance Method Details
#camelize(name) ⇒ String
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
13 14 15 |
# File 'lib/redbooth-ruby/helpers.rb', line 13 def camelize(name) name.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } end |
#underscore(camel_case_word) ⇒ String
Transform a class name into a resource name. Downcase all the letters, inserting an underscore _ before capitals Example: underscore(‘TaskList’) # => task_list
23 24 25 26 27 28 29 |
# File 'lib/redbooth-ruby/helpers.rb', line 23 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 |