Class: HashDeepDiff::Reports::Diff

Inherits:
Base
  • Object
show all
Defined in:
lib/hash_deep_diff/reports/diff.rb

Overview

Visual representation of the Delta as diff

Instance Attribute Summary

Attributes inherited from Base

#change_key, #new_val, #old_val

Instance Method Summary collapse

Methods inherited from Base

#initialize, #to_s, #to_str

Constructor Details

This class inherits a constructor from HashDeepDiff::Reports::Base

Instance Method Details

#additionString (private)

visual indication of addition

Returns:

  • (String)


36
37
38
# File 'lib/hash_deep_diff/reports/diff.rb', line 36

def addition
  '+left'
end

#deletionString (private)

visual indication of deletion

Returns:

  • (String)


42
43
44
# File 'lib/hash_deep_diff/reports/diff.rb', line 42

def deletion
  '-left'
end

#originalString (private)

old value

Returns:

  • (String)


14
15
16
17
18
# File 'lib/hash_deep_diff/reports/diff.rb', line 14

def original
  return '' if old_val == NO_VALUE

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

#pathString (private)

Visual representation of keys from compared objects needed to fetch the compared values

Returns:

  • (String)


30
31
32
# File 'lib/hash_deep_diff/reports/diff.rb', line 30

def path
  change_key.map { |key| "[#{key}]" }.join
end

#replacementString (private)

new value

Returns:

  • (String)


22
23
24
25
26
# File 'lib/hash_deep_diff/reports/diff.rb', line 22

def replacement
  return '' if new_val == NO_VALUE

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