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.



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

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



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

def add text
  add_chunk text, :added
end

#delete(text) ⇒ Object



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

def delete text
  add_chunk text, :deleted
end

#omitObject



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

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

#omits_content?Boolean

Returns:

  • (Boolean)


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

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

#renderedObject



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

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