Class: Philiprehberger::Differ::Change

Inherits:
Object
  • Object
show all
Defined in:
lib/philiprehberger/differ/change.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_valueObject (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_valueObject (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

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/philiprehberger/differ/change.rb', line 6

def path
  @path
end

#typeObject (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_hObject



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_sObject



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