13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/akatus/transferrable.rb', line 13
def to_payload(include_root = true)
class_key = self.class.name.demodulize.underscore
payload = Hash[(self.class.attributes || []).map do |attr|
attr_value = send(attr)
next if attr_value.nil?
if attr_value.respond_to?(:to_payload)
attr_value = attr_value.to_payload(false)
end
if NUMERIC_FIELDS.include?(attr)
attr_value = Akatus.format_number(attr_value)
end
if (INTEGER_FIELDS + STRING_FIELDS).include?(attr)
attr_value = attr_value.to_s
end
[ I18n.t(attr, :locale => "pt-BR", :scope => [:payload, :attributes, class_key]), attr_value ]
end]
if include_root
{ I18n.t(class_key, :locale => "pt-BR", :scope => [:payload]) => payload }
else
payload
end
end
|