Class: InspectorHashes::Inspector

Inherits:
Object
  • Object
show all
Defined in:
lib/inspector_hashes/inspector.rb

Overview

‘InspectorHashes.diff(a, b)` will return:

  • nil (if equal)

  • if given simple objects, a single difference object: “‘

    { where: '', a: a, b: b }
    

    “‘

  • if a hash or an array: the array of differences.

Constant Summary collapse

SEPARATOR =
' > '.freeze
NO_KEY =
'<<<key not present>>>'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(a:, b:, a_exists: true, b_exists: true, prefixes: []) ⇒ Inspector

Returns a new instance of Inspector.



16
17
18
19
20
21
22
# File 'lib/inspector_hashes/inspector.rb', line 16

def initialize(a:, b:, a_exists: true, b_exists: true, prefixes: [])
  self.a = a
  self.b = b
  self.a_exists = a_exists
  self.b_exists = b_exists
  self.prefixes = prefixes
end

Instance Attribute Details

#aObject

Returns the value of attribute a.



11
12
13
# File 'lib/inspector_hashes/inspector.rb', line 11

def a
  @a
end

#a_existsObject

Returns the value of attribute a_exists.



11
12
13
# File 'lib/inspector_hashes/inspector.rb', line 11

def a_exists
  @a_exists
end

#bObject

Returns the value of attribute b.



11
12
13
# File 'lib/inspector_hashes/inspector.rb', line 11

def b
  @b
end

#b_existsObject

Returns the value of attribute b_exists.



11
12
13
# File 'lib/inspector_hashes/inspector.rb', line 11

def b_exists
  @b_exists
end

#prefixesObject

Returns the value of attribute prefixes.



11
12
13
# File 'lib/inspector_hashes/inspector.rb', line 11

def prefixes
  @prefixes
end

Instance Method Details

#callObject



24
25
26
27
28
# File 'lib/inspector_hashes/inspector.rb', line 24

def call
  return nil if a_exists && b_exists && a == b

  prepare_diff
end