Sha256: 4651fd65816864b8974991825adc9ebb3999ea40eb9a86b2efbcf4a15fe8f7b0

Contents?: true

Size: 991 Bytes

Versions: 1

Compression:

Stored size: 991 Bytes

Contents

# frozen_string_literal: true

require_relative 'base'

module HashDeepDiff
  # Different reporting enjines for {Delta}
  module Reports
    # Visual representation of the {Delta} as diff
    class Diff < Base
      private

      # old value
      # @return [String]
      def original
        return '' if old_val == NO_VALUE

        return "#{deletion}#{path} = #{old_val}\n"
      end

      # new value
      # @return [String]
      def replacement
        return '' if new_val == NO_VALUE

        return "#{addition}#{path} = #{new_val}\n"
      end

      # Visual representation of keys from compared objects needed to fetch the compared values
      # @return [String]
      def path
        change_key.map { |key| "[#{key}]" }.join
      end

      # visual indication of addition
      # @return [String]
      def addition
        '+left'
      end

      # visual indication of deletion
      # @return [String]
      def deletion
        '-left'
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hash_deep_diff-0.6.0 lib/hash_deep_diff/reports/diff.rb