Class: AbideDevUtils::XCCDF::Parser::Objects::DiffableObject::DiffChangeResult
- Inherits:
-
Object
- Object
- AbideDevUtils::XCCDF::Parser::Objects::DiffableObject::DiffChangeResult
- Defined in:
- lib/abide_dev_utils/xccdf/parser/objects/diffable_object.rb
Overview
Holds the result of a diff on a per-item basis.
Instance Attribute Summary collapse
-
#details ⇒ Object
Returns the value of attribute details.
-
#element ⇒ Object
readonly
Returns the value of attribute element.
-
#new_value ⇒ Object
readonly
Returns the value of attribute new_value.
-
#old_value ⇒ Object
readonly
Returns the value of attribute old_value.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(type, old_value, new_value, element, details = {}) ⇒ DiffChangeResult
constructor
A new instance of DiffChangeResult.
- #to_a ⇒ Object
- #to_h(hash_objs: false) ⇒ Object
- #to_s ⇒ Object
- #to_yaml ⇒ Object
Constructor Details
#initialize(type, old_value, new_value, element, details = {}) ⇒ DiffChangeResult
Returns a new instance of DiffChangeResult.
39 40 41 42 43 44 45 |
# File 'lib/abide_dev_utils/xccdf/parser/objects/diffable_object.rb', line 39 def initialize(type, old_value, new_value, element, details = {}) @type = type @old_value = old_value @new_value = new_value @element = element @details = details end |
Instance Attribute Details
#details ⇒ Object
Returns the value of attribute details.
36 37 38 |
# File 'lib/abide_dev_utils/xccdf/parser/objects/diffable_object.rb', line 36 def details @details end |
#element ⇒ Object (readonly)
Returns the value of attribute element.
37 38 39 |
# File 'lib/abide_dev_utils/xccdf/parser/objects/diffable_object.rb', line 37 def element @element end |
#new_value ⇒ Object (readonly)
Returns the value of attribute new_value.
37 38 39 |
# File 'lib/abide_dev_utils/xccdf/parser/objects/diffable_object.rb', line 37 def new_value @new_value end |
#old_value ⇒ Object (readonly)
Returns the value of attribute old_value.
37 38 39 |
# File 'lib/abide_dev_utils/xccdf/parser/objects/diffable_object.rb', line 37 def old_value @old_value end |
#type ⇒ Object
Returns the value of attribute type.
36 37 38 |
# File 'lib/abide_dev_utils/xccdf/parser/objects/diffable_object.rb', line 36 def type @type end |
Instance Method Details
#to_a ⇒ Object
70 71 72 |
# File 'lib/abide_dev_utils/xccdf/parser/objects/diffable_object.rb', line 70 def to_a [type, old_value, new_value, element, details] end |
#to_h(hash_objs: false) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/abide_dev_utils/xccdf/parser/objects/diffable_object.rb', line 47 def to_h(hash_objs: false) return new_hash(type, old_value, new_value, element, details) unless hash_objs old_val = old_value.respond_to?(:to_s) ? old_value.to_s : old_value.inspect new_val = new_value.respond_to?(:to_s) ? new_value.to_s : new_value.inspect details_hash = details.transform_values do |val| case val when DiffChangeResult val.to_h(hash_objs: hash_objs) when Array val.map { |v| v.is_a?(DiffChangeResult) ? v.to_h(hash_objs: hash_objs) : v.to_s } else val.to_s end end new_hash(type, old_val, new_val, element, details_hash) end |
#to_s ⇒ Object
74 75 76 |
# File 'lib/abide_dev_utils/xccdf/parser/objects/diffable_object.rb', line 74 def to_s "#{element} #{type}: #{old_value} -> #{new_value}, #{details}" end |
#to_yaml ⇒ Object
65 66 67 68 |
# File 'lib/abide_dev_utils/xccdf/parser/objects/diffable_object.rb', line 65 def to_yaml require 'yaml' to_h(hash_objs: true).to_yaml end |