Class: AbideDevUtils::XCCDF::ChangeSet
- Inherits:
-
Object
- Object
- AbideDevUtils::XCCDF::ChangeSet
- Defined in:
- lib/abide_dev_utils/xccdf.rb
Instance Attribute Summary collapse
-
#change ⇒ Object
readonly
Returns the value of attribute change.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
-
#value_to ⇒ Object
readonly
Returns the value of attribute value_to.
Instance Method Summary collapse
- #can_merge?(other) ⇒ Boolean
-
#initialize(change:, key:, value:, value_to: nil) ⇒ ChangeSet
constructor
A new instance of ChangeSet.
- #merge(other) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(change:, key:, value:, value_to: nil) ⇒ ChangeSet
Returns a new instance of ChangeSet.
393 394 395 396 397 398 399 |
# File 'lib/abide_dev_utils/xccdf.rb', line 393 def initialize(change:, key:, value:, value_to: nil) validate_change(change) @change = change @key = key @value = value @value_to = value_to end |
Instance Attribute Details
#change ⇒ Object (readonly)
Returns the value of attribute change.
391 392 393 |
# File 'lib/abide_dev_utils/xccdf.rb', line 391 def change @change end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
391 392 393 |
# File 'lib/abide_dev_utils/xccdf.rb', line 391 def key @key end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
391 392 393 |
# File 'lib/abide_dev_utils/xccdf.rb', line 391 def value @value end |
#value_to ⇒ Object (readonly)
Returns the value of attribute value_to.
391 392 393 |
# File 'lib/abide_dev_utils/xccdf.rb', line 391 def value_to @value_to end |
Instance Method Details
#can_merge?(other) ⇒ Boolean
406 407 408 409 410 411 |
# File 'lib/abide_dev_utils/xccdf.rb', line 406 def can_merge?(other) return false unless (change == '-' && other.change == '+') || (change == '+' && other.change == '-') return false unless key == other.key || value_hash_equality(other) true end |
#merge(other) ⇒ Object
413 414 415 416 417 418 419 420 421 422 423 424 425 |
# File 'lib/abide_dev_utils/xccdf.rb', line 413 def merge(other) unless can_merge?(other) raise ArgumentError, 'Cannot merge. Possible causes: change is identical; key or value do not match' end new_to_value = value == other.value ? nil : other.value ChangeSet.new( change: '~', key: key, value: value, value_to: new_to_value ) end |
#to_s ⇒ Object
401 402 403 404 |
# File 'lib/abide_dev_utils/xccdf.rb', line 401 def to_s val_to_str = value_to.nil? ? ' ' : " to #{value_to} " "#{change_string} value #{value}#{val_to_str}at #{key}" end |