Class: IRT::Differ

Inherits:
Object show all
Defined in:
lib/irt/differ.rb

Defined Under Namespace

Modules: Format

Instance Method Summary collapse

Constructor Details

#initialize(a, b, kind = :value, options = {}) ⇒ Differ

Returns a new instance of Differ.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/irt/differ.rb', line 5

def initialize(a, b, kind=:value, options={})
  if kind == :value
    a = IRT.yaml_dump a
    b = IRT.yaml_dump b
  end
  @a = a
  @b = b
  @options = { :a_label  => 'saved',
               :b_label  => 'actual',
               :a_marker => '~',
               :b_marker => '!' }.merge options
  IRT::Differ::Format.options = @options
  @diff = ::Differ.(@b, @a)
end

Instance Method Details

#outputObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/irt/differ.rb', line 20

def output
  out = "\n"
  out << IRT.dye(' = same ', :reversed, :bold)
  a = "#{@options[:a_marker]} #{@options[:a_label]}"
  out << IRT.dye(" #{a} ", " (#{a}) ", :diff_a_color, :reversed, :bold)
  b = "#{@options[:b_marker]} #{@options[:b_label]}"
  out << IRT.dye(" #{b} ", " (#{b}) ", :diff_b_color, :reversed, :bold)
  out << "\n"
  diff = @diff.format_as(IRT::Differ::Format)
  out << diff.sub(/^\n/,'')
  out << "\n"
  out
end