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
# File 'lib/card/content/diff/summary.rb', line 6

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

Instance Method Details

#add(text) ⇒ Object



17
18
19
# File 'lib/card/content/diff/summary.rb', line 17

def add text
  add_chunk text, :added
end

#delete(text) ⇒ Object



21
22
23
# File 'lib/card/content/diff/summary.rb', line 21

def delete text
  add_chunk text, :deleted
end

#omitObject



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

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

  add_chunk @joint, :ellipsis
end

#omits_content?Boolean

Returns:

  • (Boolean)


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

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

#renderedObject



13
14
15
# File 'lib/card/content/diff/summary.rb', line 13

def rendered
  @rendered ||= render
end