Class: Card::Content::Diff

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

Overview

handle comparisons of card content

Defined Under Namespace

Classes: LCS, Result, Summary

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(old_version, new_version, opts = {}) ⇒ Diff

diff options :format => :html|:text|:pointer|:raw

:html    = maintain html structure, but compare only content
:text    = remove all html tags; compare plain text
:pointer = remove all double square brackets
:raw     = escape html tags and compare everything

summary: {length: <number> , joint: <string> }



37
38
39
40
41
42
43
# File 'lib/card/content/diff.rb', line 37

def initialize old_version, new_version, opts={}
  @result = Result.new opts[:summary]
  return unless new_version

  lcs_opts = lcs_opts_for_format opts[:diff_format]
  LCS.new(lcs_opts).run(old_version, new_version, @result)
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



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

def result
  @result
end

Class Method Details

.complete(a, b, opts = {}) ⇒ Object



8
9
10
# File 'lib/card/content/diff.rb', line 8

def complete a, b, opts={}
  Card::Content::Diff.new(a, b, opts).complete
end

.render_added_chunk(text) ⇒ Object



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

def render_added_chunk text
  "<ins class='diffins diff-added'>#{text}</ins>"
end

.render_deleted_chunk(text, _count = true) ⇒ Object



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

def render_deleted_chunk text, _count=true
  "<del class='diffdel diff-deleted'>#{text}</del>"
end

.summary(a, b, opts = {}) ⇒ Object



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

def summary a, b, opts={}
  Card::Content::Diff.new(a, b, opts).summary
end

Instance Method Details

#green?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/card/content/diff.rb', line 49

def green?
  @result.adds_cnt.positive?
end

#red?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/card/content/diff.rb', line 45

def red?
  @result.dels_cnt.positive?
end