Class: LedgerSync::QuickBooksOnline::Deserializer
- Inherits:
-
Deserializer
- Object
- Deserializer
- LedgerSync::QuickBooksOnline::Deserializer
show all
- Defined in:
- lib/ledger_sync/quickbooks_online/deserializer.rb
Direct Known Subclasses
Account::Deserializer, AccountBasedExpenseLineDetail::Deserializer, Bill::Deserializer, BillLine::Deserializer, BillPayment::Deserializer, BillPaymentLine::Deserializer, CheckPayment::Deserializer, CreditCardPayment::Deserializer, Currency::Deserializer, Customer::Deserializer, LedgerSync::QuickBooksOnline::Department::Deserializer, LedgerSync::QuickBooksOnline::Deposit::Deserializer, LedgerSync::QuickBooksOnline::DepositLine::Deserializer, LedgerSync::QuickBooksOnline::DepositLineDetail::Deserializer, Expense::Deserializer, ExpenseLine::Deserializer, Invoice::Deserializer, InvoiceLine::Deserializer, Item::Deserializer, JournalEntry::Deserializer, JournalEntryLine::Deserializer, JournalEntryLineDetail::Deserializer, LedgerClass::Deserializer, Payment::Deserializer, PaymentLine::Deserializer, Preferences::Deserializer, PrimaryEmailAddr::Deserializer, PrimaryPhone::Deserializer, Reference::Deserializer, SalesItemLineDetail::Deserializer, Transfer::Deserializer, Vendor::Deserializer
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.amount(resource_attribute, args = {}) ⇒ Object
74
75
76
77
78
79
80
81
|
# File 'lib/ledger_sync/quickbooks_online/deserializer.rb', line 74
def self.amount(resource_attribute, args = {})
attribute(
resource_attribute,
{
type: Serialization::Type::AmountFloatToIntegerType.new
}.merge(args)
)
end
|
.date(resource_attribute, args = {}) ⇒ Object
83
84
85
86
87
88
89
90
|
# File 'lib/ledger_sync/quickbooks_online/deserializer.rb', line 83
def self.date(resource_attribute, args = {})
attribute(
resource_attribute,
{
type: LedgerSync::Serialization::Type::ParseDateType.new(format: '%Y-%m-%d')
}.merge(args)
)
end
|
.id ⇒ Object
92
93
94
|
# File 'lib/ledger_sync/quickbooks_online/deserializer.rb', line 92
def self.id
attribute(:ledger_id, hash_attribute: 'Id')
end
|
Instance Method Details
#deserialize(args = {}) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/ledger_sync/quickbooks_online/deserializer.rb', line 8
def deserialize(args = {})
hash = args.fetch(:hash)
merge_for_full_update = args.fetch(:merge_for_full_update, false)
resource = args.fetch(:resource)
deserialized_resource = super(hash: hash, resource: resource)
if deserialized_resource.is_a?(LedgerSync::QuickBooksOnline::Account) &&
deserialized_resource.AccountType &&
deserialized_resource.Classification.blank?
deserialized_resource.Classification = deserialized_resource.class::TYPES_TO_CLASSIFICATION_MAPPING.fetch(
deserialized_resource.AccountType,
nil
)
end
return deserialized_resource unless merge_for_full_update
merge_resources_for_full_update(
hash: hash,
ledger_resource: deserialized_resource,
resource: resource
)
end
|
#merge_resources_for_full_update(args = {}) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/ledger_sync/quickbooks_online/deserializer.rb', line 34
def merge_resources_for_full_update(args = {})
hash = args.fetch(:hash)
resource = args.fetch(:resource)
merged_resource = resource.dup
self.class.attributes.each do |_key, deserializer_attribute|
next unless deserializer_attribute.references_many?
resources_from_ledger = attribute_value_from_ledger(
hash: hash,
deserializer_attribute: deserializer_attribute,
resource: merged_resource
)
resource_hash_from_ledger = resources_from_ledger.map { |e| [e.ledger_id, e] }.to_h
merged_value = resource.send(deserializer_attribute.resource_attribute_dot_parts.first).map do |referenced|
if referenced.ledger_id.nil? referenced
elsif resource_hash_from_ledger.key?(referenced.ledger_id.to_s) ledger_resource = resource_hash_from_ledger[referenced.ledger_id.to_s]
ledger_resource_serializer = deserializer_attribute.type.deserializer.inferred_serializer_class.new
deserializer_attribute.type.deserializer.new.deserialize(
hash: ledger_resource_serializer.serialize(resource: ledger_resource),
resource: referenced
)
end
end.compact
merged_resource.assign_attribute(
deserializer_attribute.resource_attribute_dot_parts.first,
merged_value
)
end
merged_resource
end
|