Class: AbideDevUtils::XCCDF::Parser::Objects::DiffableObject::DiffChangeResult

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#detailsObject

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

#elementObject (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_valueObject (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_valueObject (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

#typeObject

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_aObject



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_sObject



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_yamlObject



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