Module: RedboothRuby::Helpers

Included in:
Client, ClientOperations::Perform, Operations::Base::ClassMethods, Request::Collection
Defined in:
lib/redbooth-ruby/helpers.rb

Instance Method Summary collapse

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

Parameters:

  • name (Symbol|String)

    to convert

Returns:

  • (String)

    string of the class name



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

Parameters:

  • camel_case_word (String)

    to convert

Returns:

  • (String)

    string of the resource name



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