Module: Apia::Helpers

Defined in:
lib/apia/helpers.rb

Class Method Summary collapse

Class Method Details

.camelize(string) ⇒ String?

Convert a string into CamelCase

Parameters:

  • string (String, nil)

Returns:

  • (String, nil)


22
23
24
25
26
27
28
29
# File 'lib/apia/helpers.rb', line 22

def camelize(string)
  return nil if string.nil?

  string = string.to_s.sub(/^[a-z\d]*/) { |match| match.capitalize }
  string.gsub(/(?:_)([a-z\d]*)/) do
    Regexp.last_match(1).capitalize.to_s
  end
end

.class_name_to_id(name) ⇒ String

Convert a ruby class name into an ID for use by objects

Parameters:

  • name (String)

Returns:

  • (String)


14
15
16
# File 'lib/apia/helpers.rb', line 14

def class_name_to_id(name)
  name.to_s.gsub('::', '/')
end