Class: Card::Diff::Result::Summary
Instance Method Summary collapse
- #add(text) ⇒ Object
- #delete(text) ⇒ Object
-
#initialize(opts) ⇒ Summary
constructor
A new instance of Summary.
- #omit ⇒ Object
- #rendered ⇒ Object
Constructor Details
#initialize(opts) ⇒ Summary
Returns a new instance of Summary.
38 39 40 41 42 43 44 45 |
# File 'lib/card/diff/result.rb', line 38 def initialize opts opts ||= {} @remaining_chars = opts[:length] || 50 @joint = opts[:joint] || '...' @summary = nil @chunks = [] end |
Instance Method Details
#add(text) ⇒ Object
57 58 59 |
# File 'lib/card/diff/result.rb', line 57 def add text add_chunk text, :added end |
#delete(text) ⇒ Object
61 62 63 |
# File 'lib/card/diff/result.rb', line 61 def delete text add_chunk text, :deleted end |
#omit ⇒ Object
65 66 67 68 69 |
# File 'lib/card/diff/result.rb', line 65 def omit if @chunks.empty? || @chunks.last[:action] != :ellipsis add_chunk @joint, :ellipsis end end |
#rendered ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/card/diff/result.rb', line 47 def rendered @summary ||= begin truncate_overlap @chunks.map do |chunk| render_chunk chunk[:action], chunk[:text] end.join end end |