Class: PatienceDiff::Html::HunkHelper

Inherits:
Object
  • Object
show all
Includes:
Escaping
Defined in:
lib/patience_diff/html/hunk_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Escaping

#escape

Constructor Details

#initialize(a, b, hunk_marker, opcodes, last_hunk_end, hunk_id) ⇒ HunkHelper

Returns a new instance of HunkHelper.



9
10
11
12
13
14
15
16
# File 'lib/patience_diff/html/hunk_helper.rb', line 9

def initialize(a, b, hunk_marker, opcodes, last_hunk_end, hunk_id)
  @a = a
  @b = b
  @hunk_marker = hunk_marker
  @opcodes = opcodes
  @last_hunk_end = last_hunk_end
  @hunk_id = hunk_id
end

Instance Attribute Details

#aObject

Returns the value of attribute a.



7
8
9
# File 'lib/patience_diff/html/hunk_helper.rb', line 7

def a
  @a
end

#bObject

Returns the value of attribute b.



7
8
9
# File 'lib/patience_diff/html/hunk_helper.rb', line 7

def b
  @b
end

#hunk_idObject

Returns the value of attribute hunk_id.



7
8
9
# File 'lib/patience_diff/html/hunk_helper.rb', line 7

def hunk_id
  @hunk_id
end

#hunk_markerObject

Returns the value of attribute hunk_marker.



7
8
9
# File 'lib/patience_diff/html/hunk_helper.rb', line 7

def hunk_marker
  @hunk_marker
end

#last_hunk_endObject

Returns the value of attribute last_hunk_end.



7
8
9
# File 'lib/patience_diff/html/hunk_helper.rb', line 7

def last_hunk_end
  @last_hunk_end
end

#opcodesObject

Returns the value of attribute opcodes.



7
8
9
# File 'lib/patience_diff/html/hunk_helper.rb', line 7

def opcodes
  @opcodes
end

Instance Method Details

#each_lineObject



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/patience_diff/html/hunk_helper.rb', line 30

def each_line
  opcodes.each do |(code, a_start, a_end, b_start, b_end)|
    case code
    when :delete
      a[a_start..a_end].each { |line| yield 'delete', '-' + format_line(line) }
    when :equal
      b[b_start..b_end].each { |line| yield 'equal',  ' ' + format_line(line) }
    when :insert
      b[b_start..b_end].each { |line| yield 'insert', '+' + format_line(line) }
    end
  end
end

#hidden_line_countObject



22
23
24
# File 'lib/patience_diff/html/hunk_helper.rb', line 22

def hidden_line_count
  hunk_start - @last_hunk_end - 1
end

#hunk_startObject



18
19
20
# File 'lib/patience_diff/html/hunk_helper.rb', line 18

def hunk_start
  @opcodes.first[3]
end

#linesObject



26
27
28
# File 'lib/patience_diff/html/hunk_helper.rb', line 26

def lines
  @b
end