Module: Camunda::Util

Defined in:
lib/camunda/util.rb

Class Method Summary collapse

Class Method Details

.underscore(camel_cased_word) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/camunda/util.rb', line 12

def self.underscore(camel_cased_word)
  return camel_cased_word unless camel_cased_word =~ /[A-Z-]/

  word = camel_cased_word.to_s.gsub(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
  word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
  word.tr!('-', '_')
  word.tr!(' ', '_')
  word.downcase!
  word
end

.underscorize_hash(attributes) ⇒ Object



6
7
8
9
10
# File 'lib/camunda/util.rb', line 6

def self.underscorize_hash(attributes)
  attributes.keys.each_with_object({}) do |key, result|
    result[underscore(key)] = attributes[key]
  end
end