Class: ChangeHealth::Models::Model
- Inherits:
-
Hashie::Trash
- Object
- Hashie::Trash
- ChangeHealth::Models::Model
show all
- Defined in:
- lib/change_health/models/model.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.hashify(model) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/change_health/models/model.rb', line 39
def self.hashify(model)
model.map do |key, value|
formatted_value = case value
when Hash
hashify(model[key])
when Array
value.map do |element|
if element.is_a?(Hash)
hashify(element)
else format_value(key, element)
end
end
else
format_value(key, value)
end
[key, formatted_value]
end.to_h
end
|
Instance Method Details
#as_json(_args = {}) ⇒ Object
68
69
70
|
# File 'lib/change_health/models/model.rb', line 68
def as_json(_args = {})
to_h
end
|
#to_h ⇒ Object
35
36
37
|
# File 'lib/change_health/models/model.rb', line 35
def to_h
self.class.hashify(self)
end
|
#to_json(*_args) ⇒ Object
72
73
74
|
# File 'lib/change_health/models/model.rb', line 72
def to_json(*_args)
to_h.to_json
end
|