Class: Card::Diff

Inherits:
Object show all
Defined in:
lib/card/diff.rb,
lib/card/diff/lcs.rb,
lib/card/diff/result.rb

Defined Under Namespace

Classes: LCS, Result

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> }



35
36
37
38
39
40
41
# File 'lib/card/diff.rb', line 35

def initialize old_version, new_version, opts={}
  @result = Result.new opts[:summary]
  if new_version
    lcs_opts = lcs_opts_for_format opts[:format]
    LCS.new(lcs_opts).run(old_version, new_version, @result)
  end
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



23
24
25
# File 'lib/card/diff.rb', line 23

def result
  @result
end

Class Method Details

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



6
7
8
# File 'lib/card/diff.rb', line 6

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

.render_added_chunk(text) ⇒ Object



14
15
16
# File 'lib/card/diff.rb', line 14

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

.render_deleted_chunk(text, _count = true) ⇒ Object



18
19
20
# File 'lib/card/diff.rb', line 18

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

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



10
11
12
# File 'lib/card/diff.rb', line 10

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

Instance Method Details

#green?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/card/diff.rb', line 47

def green?
  @result.adds_cnt > 0
end

#red?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/card/diff.rb', line 43

def red?
  @result.dels_cnt > 0
end