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

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

Overview

Summary object for Diff processing

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Summary

Returns a new instance of Summary.



6
7
8
9
10
11
12
13
14
# File 'lib/card/content/diff/summary.rb', line 6

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

  @summary = nil
  @chunks = []
  @content_omitted = false
end

Instance Method Details

#add(text) ⇒ Object



27
28
29
# File 'lib/card/content/diff/summary.rb', line 27

def add text
  add_chunk text, :added
end

#delete(text) ⇒ Object



31
32
33
# File 'lib/card/content/diff/summary.rb', line 31

def delete text
  add_chunk text, :deleted
end

#omitObject



35
36
37
38
39
# File 'lib/card/content/diff/summary.rb', line 35

def omit
  return unless @chunks.empty? || @chunks.last[:action] != :ellipsis

  add_chunk @joint, :ellipsis
end

#omits_content?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/card/content/diff/summary.rb', line 41

def omits_content?
  @content_omitted || @remaining_chars.negative?
end

#renderedObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/card/content/diff/summary.rb', line 16

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