Class: Card::Diff::Result::Summary

Inherits:
Object
  • Object
show all
Defined in:
lib/card/diff/result.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Summary

Returns a new instance of Summary.



38
39
40
41
42
43
44
45
# File 'lib/card/diff/result.rb', line 38

def initialize opts
  opts ||= {}
  @remaining_chars = opts[:length] || 50
  @joint = opts[:joint] || '...'

  @summary = nil
  @chunks = []
end

Instance Method Details

#add(text) ⇒ Object



57
58
59
# File 'lib/card/diff/result.rb', line 57

def add text
  add_chunk text, :added
end

#delete(text) ⇒ Object



61
62
63
# File 'lib/card/diff/result.rb', line 61

def delete text
  add_chunk text, :deleted
end

#omitObject



65
66
67
68
69
# File 'lib/card/diff/result.rb', line 65

def omit
  if @chunks.empty? || @chunks.last[:action] != :ellipsis
    add_chunk @joint, :ellipsis
  end
end

#renderedObject



47
48
49
50
51
52
53
54
55
# File 'lib/card/diff/result.rb', line 47

def rendered
  @summary ||=
    begin
      truncate_overlap
      @chunks.map do |chunk|
        render_chunk chunk[:action], chunk[:text]
      end.join
    end
end