Class: RSpec::JsonMatcher::AbstractComparer

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/json_matcher/abstract_comparer.rb

Direct Known Subclasses

ExactComparer, FuzzyComparer

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(actual, expected, &reason) ⇒ AbstractComparer

Returns a new instance of AbstractComparer.



18
19
20
21
22
# File 'lib/rspec/json_matcher/abstract_comparer.rb', line 18

def initialize(actual, expected, &reason)
  @actual   = actual
  @expected = expected
  @reason   = reason
end

Instance Attribute Details

#actualObject (readonly)

Returns the value of attribute actual.



4
5
6
# File 'lib/rspec/json_matcher/abstract_comparer.rb', line 4

def actual
  @actual
end

#expectedObject (readonly)

Returns the value of attribute expected.



4
5
6
# File 'lib/rspec/json_matcher/abstract_comparer.rb', line 4

def expected
  @expected
end

#reasonObject (readonly)

Returns the value of attribute reason.



4
5
6
# File 'lib/rspec/json_matcher/abstract_comparer.rb', line 4

def reason
  @reason
end

Class Method Details

.compare(*args, &reason) ⇒ Object



6
7
8
# File 'lib/rspec/json_matcher/abstract_comparer.rb', line 6

def self.compare(*args, &reason)
  new(*args, &reason).compare
end

.extract_keys(array_or_hash) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/rspec/json_matcher/abstract_comparer.rb', line 10

def self.extract_keys(array_or_hash)
  if array_or_hash.is_a?(Array)
    array_or_hash.each_index.to_a
  else
    array_or_hash.keys.map(&:to_s)
  end
end

Instance Method Details

#compareObject



24
25
26
# File 'lib/rspec/json_matcher/abstract_comparer.rb', line 24

def compare
  has_same_value? || has_same_collection?
end