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

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

Overview

Summary object for Diff processing

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Summary

Returns a new instance of Summary.



41
42
43
44
45
46
47
48
# File 'lib/card/content/diff/result.rb', line 41

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

  @summary = nil
  @chunks = []
end

Instance Method Details

#add(text) ⇒ Object



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

def add text
  add_chunk text, :added
end

#delete(text) ⇒ Object



64
65
66
# File 'lib/card/content/diff/result.rb', line 64

def delete text
  add_chunk text, :deleted
end

#omitObject



68
69
70
71
72
# File 'lib/card/content/diff/result.rb', line 68

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

#renderedObject



50
51
52
53
54
55
56
57
58
# File 'lib/card/content/diff/result.rb', line 50

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