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.



45
46
47
48
49
50
51
52
53
# File 'lib/card/content/diff/result.rb', line 45

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



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

def add text
  add_chunk text, :added
end

#delete(text) ⇒ Object



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

def delete text
  add_chunk text, :deleted
end

#omitObject



74
75
76
77
78
# File 'lib/card/content/diff/result.rb', line 74

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

#omits_content?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/card/content/diff/result.rb', line 80

def omits_content?
  @content_omitted || @remaining_chars < 0
end

#renderedObject



55
56
57
58
59
60
61
62
63
64
# File 'lib/card/content/diff/result.rb', line 55

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