Module: NormalizrRuby::KeyTransform

Defined in:
lib/normalizr_ruby/key_transform.rb

Class Method Summary collapse

Class Method Details

.camel(value) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/normalizr_ruby/key_transform.rb', line 5

def camel(value)
  case value
  when Hash then value.deep_transform_keys! { |key| camel(key) }
  when Symbol then camel(value.to_s).to_sym
  when String then value.underscore.camelize
  else value
  end
end

.camel_lower(value) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/normalizr_ruby/key_transform.rb', line 14

def camel_lower(value)
  case value
  when Hash then value.deep_transform_keys! { |key| camel_lower(key) }
  when Symbol then camel_lower(value.to_s).to_sym
  when String then value.underscore.camelize(:lower)
  else value
  end
end

.dash(value) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/normalizr_ruby/key_transform.rb', line 23

def dash(value)
  case value
  when Hash then value.deep_transform_keys! { |key| dash(key) }
  when Symbol then dash(value.to_s).to_sym
  when String then value.underscore.dasherize
  else value
  end
end

.unaltered(value) ⇒ Object



41
42
43
# File 'lib/normalizr_ruby/key_transform.rb', line 41

def unaltered(value)
  value
end

.underscore(value) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/normalizr_ruby/key_transform.rb', line 32

def underscore(value)
  case value
  when Hash then value.deep_transform_keys! { |key| underscore(key) }
  when Symbol then underscore(value.to_s).to_sym
  when String then value.underscore
  else value
  end
end