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.



402
403
404
405
406
407
408
# File 'lib/abide_dev_utils/xccdf.rb', line 402

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.



400
401
402
# File 'lib/abide_dev_utils/xccdf.rb', line 400

def change
  @change
end

#keyObject (readonly)

Returns the value of attribute key.



400
401
402
# File 'lib/abide_dev_utils/xccdf.rb', line 400

def key
  @key
end

#valueObject (readonly)

Returns the value of attribute value.



400
401
402
# File 'lib/abide_dev_utils/xccdf.rb', line 400

def value
  @value
end

#value_toObject (readonly)

Returns the value of attribute value_to.



400
401
402
# File 'lib/abide_dev_utils/xccdf.rb', line 400

def value_to
  @value_to
end

Instance Method Details

#can_merge?(other) ⇒ Boolean

Returns:

  • (Boolean)


415
416
417
418
419
420
# File 'lib/abide_dev_utils/xccdf.rb', line 415

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



422
423
424
425
426
427
428
429
430
431
432
433
434
# File 'lib/abide_dev_utils/xccdf.rb', line 422

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



410
411
412
413
# File 'lib/abide_dev_utils/xccdf.rb', line 410

def to_s
  val_to_str = value_to.nil? ? ' ' : " to #{value_to} "
  "#{change_string} value #{value}#{val_to_str}at #{key}"
end