Sha256: 4faea162fdfa7e866b05193539e896d9792807fa93bf9ec4c6cb8491bc32da8f

Contents?: true

Size: 1.5 KB

Versions: 5

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true

module LedgerSync
  module Adaptors
    module QuickBooksOnline
      module LedgerSerializerType
        class TransactionReferenceType < Adaptors::LedgerSerializerType::ValueType
          def convert_from_ledger(value:)
            return if value.nil?

            raise "Unknown value type.  Array expected.  Given: #{value.class.name}" unless value.is_a?(Array)
            return if value.empty?

            value.map do |item|
              resource_class = Adaptor.resource_from_ledger_type(type: item['TxnType'])

              raise "Unknown QuickBooks Online resource type: #{item['TxnType']}" if resource_class.blank?

              resource_class.new(
                ledger_id: item['TxnId']
              )
            end
          end

          def convert_from_local(value:)
            return if value.nil?
            raise "List expected.  Given: #{value.class.name}" unless value.is_a?(Array)
            raise "Resources expected.  Given: #{value.map { |i| i.class.name }.join(', ')}" unless value.all?(LedgerSync::Resource)

            value.map do |resource|
              {
                'TxnId' => resource.ledger_id,
                'TxnType' => Adaptor.ledger_resource_type_for(
                  resource_class: resource.class
                ).classify
              }
            end
          end

          private

          def string_helpers
            @string_helpers ||= LedgerSync::Util::StringHelpers
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ledger_sync-1.3.5 lib/ledger_sync/adaptors/quickbooks_online/ledger_serializer_type/transaction_reference_type.rb
ledger_sync-1.3.4 lib/ledger_sync/adaptors/quickbooks_online/ledger_serializer_type/transaction_reference_type.rb
ledger_sync-1.3.3 lib/ledger_sync/adaptors/quickbooks_online/ledger_serializer_type/transaction_reference_type.rb
ledger_sync-1.3.2 lib/ledger_sync/adaptors/quickbooks_online/ledger_serializer_type/transaction_reference_type.rb
ledger_sync-1.3.1 lib/ledger_sync/adaptors/quickbooks_online/ledger_serializer_type/transaction_reference_type.rb