Class: Specdiff::Compare

Inherits:
Object
  • Object
show all
Defined in:
lib/specdiff/compare.rb

Defined Under Namespace

Classes: Side

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.callObject



4
5
6
# File 'lib/specdiff/compare.rb', line 4

def self.call(...)
  new.call(...)
end

Instance Method Details

#call(raw_a, raw_b) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/specdiff/compare.rb', line 8

def call(raw_a, raw_b)
  a = parse_side(raw_a)
  b = parse_side(raw_b)

  if a.type == :text && b.type == :binary
    new_b = try_reencode(b.value, a.value.encoding)
    if new_b
      b = b.dup
      b.type = :text
      b.value = new_b
    end
  elsif a.type == :binary && b.type == :text
    new_a = try_reencode(a.value, b.value.encoding)
    if new_a
      a = a.dup
      a.type = :text
      a.value = new_a
    end
  end

  differ = pick_differ(a, b)
  raw = differ.diff(a, b)

  if raw.is_a?(::Specdiff::Diff) # detect recursive plugins, such as json
    raw
  else
    ::Specdiff::Diff.new(raw: raw, differ: differ, a: a, b: b)
  end
end