Class: AbideDevUtils::XCCDF::ChangeSet

Inherits:
Object
  • Object
show all
Defined in:
lib/abide_dev_utils/xccdf.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#changeObject (readonly)

Returns the value of attribute change.



391
392
393
# File 'lib/abide_dev_utils/xccdf.rb', line 391

def change
  @change
end

#keyObject (readonly)

Returns the value of attribute key.



391
392
393
# File 'lib/abide_dev_utils/xccdf.rb', line 391

def key
  @key
end

#valueObject (readonly)

Returns the value of attribute value.



391
392
393
# File 'lib/abide_dev_utils/xccdf.rb', line 391

def value
  @value
end

#value_toObject (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

Returns:

  • (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_sObject



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