Class: Philiprehberger::Differ::Change
- Inherits:
-
Object
- Object
- Philiprehberger::Differ::Change
- Defined in:
- lib/philiprehberger/differ/change.rb
Instance Attribute Summary collapse
-
#new_value ⇒ Object
readonly
Returns the value of attribute new_value.
-
#old_value ⇒ Object
readonly
Returns the value of attribute old_value.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(path:, type:, old_value: nil, new_value: nil) ⇒ Change
constructor
A new instance of Change.
- #to_h ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(path:, type:, old_value: nil, new_value: nil) ⇒ Change
Returns a new instance of Change.
8 9 10 11 12 13 |
# File 'lib/philiprehberger/differ/change.rb', line 8 def initialize(path:, type:, old_value: nil, new_value: nil) @path = path @type = type @old_value = old_value @new_value = new_value end |
Instance Attribute Details
#new_value ⇒ Object (readonly)
Returns the value of attribute new_value.
6 7 8 |
# File 'lib/philiprehberger/differ/change.rb', line 6 def new_value @new_value end |
#old_value ⇒ Object (readonly)
Returns the value of attribute old_value.
6 7 8 |
# File 'lib/philiprehberger/differ/change.rb', line 6 def old_value @old_value end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/philiprehberger/differ/change.rb', line 6 def path @path end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'lib/philiprehberger/differ/change.rb', line 6 def type @type end |
Instance Method Details
#to_h ⇒ Object
23 24 25 |
# File 'lib/philiprehberger/differ/change.rb', line 23 def to_h { path: path, type: type, old_value: old_value, new_value: new_value } end |
#to_s ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/philiprehberger/differ/change.rb', line 15 def to_s case type when :added then "Added #{path}: #{new_value.inspect}" when :removed then "Removed #{path}: #{old_value.inspect}" when :changed then "Changed #{path}: #{old_value.inspect} -> #{new_value.inspect}" end end |