Sha256: 32e19c617f26766423c5190e181501ac410366bf035f9777e238eba9d3bdfd9c

Contents?: true

Size: 973 Bytes

Versions: 7

Compression:

Stored size: 973 Bytes

Contents

# frozen_string_literal: true

module LedgerSync
  module Adaptors
    module LedgerSerializerType
      class MappingType < ValueType
        attr_reader :source, :value

        def self.mapping
          @mapping ||= begin
            raise NotImplementedError
          end
        end

        def convert_from_ledger(value:)
          return if value.nil?
          raise "Ledger to local mapping not found: #{value}" unless reverse_mapping_hash.key?(value)

          reverse_mapping_hash[value]
        end

        def convert_from_local(value:)
          return if value.nil?
          raise "Local to ledger mapping not found: #{value}" unless mapping_hash.key?(value)

          mapping_hash[value]
        end

        private

        def mapping_hash
          @mapping_hash ||= self.class.mapping
        end

        def reverse_mapping_hash
          @reverse_mapping_hash ||= mapping_hash.to_a.map(&:reverse).to_h
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ledger_sync-1.3.5 lib/ledger_sync/adaptors/ledger_serializer_type/mapping_type.rb
ledger_sync-1.3.4 lib/ledger_sync/adaptors/ledger_serializer_type/mapping_type.rb
ledger_sync-1.3.3 lib/ledger_sync/adaptors/ledger_serializer_type/mapping_type.rb
ledger_sync-1.3.2 lib/ledger_sync/adaptors/ledger_serializer_type/mapping_type.rb
ledger_sync-1.3.1 lib/ledger_sync/adaptors/ledger_serializer_type/mapping_type.rb
ledger_sync-1.1.3 lib/ledger_sync/adaptors/ledger_serializer_type/mapping_type.rb
ledger_sync-1.1.2 lib/ledger_sync/adaptors/ledger_serializer_type/mapping_type.rb