Class: HashDeepDiff::Report
- Inherits:
-
Object
- Object
- HashDeepDiff::Report
- Defined in:
- lib/hash_deep_diff/report.rb
Overview
Visual representation of the difference between two values
Defined Under Namespace
Modules: Mode
Instance Method Summary collapse
-
#diff_prefix ⇒ String
private
Visual representation of keys from compared objects needed to fetch the compared values.
-
#initialize(path:, value:, mode: Mode::ADDITION) ⇒ Report
constructor
private
A new instance of Report.
-
#to_s ⇒ String
A report with all additions and deletions.
-
#to_str ⇒ String
A report with all additions and deletions.
Constructor Details
Instance Method Details
#diff_prefix ⇒ String (private)
Visual representation of keys from compared objects needed to fetch the compared values
48 49 50 51 |
# File 'lib/hash_deep_diff/report.rb', line 48 def diff_prefix # TOFIX poor naming @path.map { |key| "[#{key}]" }.join end |
#to_s ⇒ String
A report with all additions and deletions
31 32 33 |
# File 'lib/hash_deep_diff/report.rb', line 31 def to_s to_str end |
#to_str ⇒ String
A report with all additions and deletions
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/hash_deep_diff/report.rb', line 18 def to_str if @value.respond_to?(:to_hash) && !@value.empty? [@mode, diff_prefix, ' = ', "{}\n"].join + @value.keys.map do |key| Report.new(path: @path + [key], value: @value[key], mode: @mode) end.join("\n") else [@mode, diff_prefix, ' = ', @value.to_s].join end end |