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.
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
#change ⇒ Object (readonly)
Returns the value of attribute change.
400 401 402 |
# File 'lib/abide_dev_utils/xccdf.rb', line 400 def change @change end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
400 401 402 |
# File 'lib/abide_dev_utils/xccdf.rb', line 400 def key @key end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
400 401 402 |
# File 'lib/abide_dev_utils/xccdf.rb', line 400 def value @value end |
#value_to ⇒ Object (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
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_s ⇒ Object
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 |