Class: HashDeepDiff::Reports::Yml

Inherits:
Base
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/hash_deep_diff/reports/yml.rb

Overview

Visual representation of the Delta as diff

Instance Attribute Summary collapse

Attributes inherited from Base

#diff

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 Attribute Details

#rawObject (readonly, private)

Returns the value of attribute raw.



34
35
36
# File 'lib/hash_deep_diff/reports/yml.rb', line 34

def raw
  @raw
end

Instance Method Details

#additionsArray<HashDeepDiff::Delta> (private)

added values

Returns:



38
39
40
41
42
# File 'lib/hash_deep_diff/reports/yml.rb', line 38

def additions
  diff.reject { |delta| delta.right == NO_VALUE }
      .map { |delta| [delta.change_key, delta.addition] }
      .reject { |(_, addition)| [] == addition }
end

#deletionsArray<HashDeepDiff::Delta> (private)

deleted values

Returns:



46
47
48
49
50
# File 'lib/hash_deep_diff/reports/yml.rb', line 46

def deletions
  diff.reject { |delta| delta.left == NO_VALUE }
      .map { |delta| [delta.change_key, delta.deletion] }
      .reject { |(_, deletion)| [] == deletion }
end

#raw_reportHash

additions and deletiond represented as Hash

Returns:

  • (Hash)


23
24
25
26
27
28
29
30
# File 'lib/hash_deep_diff/reports/yml.rb', line 23

def raw_report
  @raw = { 'additions' => initial_object(values: additions), 'deletions' => initial_object(values: deletions) }

  additions.each { |(change_key, addition)| change_key.set(raw['additions'], addition) }
  deletions.each { |(change_key, deletion)| change_key.set(raw['deletions'], deletion) }

  return raw
end

#reportString

additions and deletions represented as YAML

Returns:

  • (String)


17
18
19
# File 'lib/hash_deep_diff/reports/yml.rb', line 17

def report
  YAML.dump(raw_report)
end