Class: Redmine::DiffTable

Inherits:
Array
  • Object
show all
Defined in:
lib/redmine/diff_table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from StringArrayDiff::Diffable

#diff, #patch, #replacenextlarger, #reverse_hash

Constructor Details

#initialize(type = "inline", style = nil) ⇒ DiffTable

Initialize with a Diff file and the type of Diff View The type view must be inline or sbs (side_by_side)



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/redmine/diff_table.rb', line 27

def initialize(type="inline", style=nil)
  super()
  @parsing = false
  @added = 0
  @removed = 0
  @type = type
  @style = style
  @file_name = nil
  @previous_file_name = nil
  @git_diff = false
end

Instance Attribute Details

#file_nameObject

Returns the value of attribute file_name.



23
24
25
# File 'lib/redmine/diff_table.rb', line 23

def file_name
  @file_name
end

#previous_file_nameObject (readonly)

Returns the value of attribute previous_file_name.



23
24
25
# File 'lib/redmine/diff_table.rb', line 23

def previous_file_name
  @previous_file_name
end

Instance Method Details

#add_line(line) ⇒ Object

Function for add a line of this Diff Returns false when the diff ends



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/redmine/diff_table.rb', line 41

def add_line(line)
  unless @parsing
    if line =~ /^(---|\+\+\+) (.*)$/
      self.file_name = $2
    elsif line =~ /^@@ (\+|\-)(\d+)(,\d+)? (\+|\-)(\d+)(,\d+)? @@/
      @line_num_l = $2.to_i
      @line_num_r = $5.to_i
      @parsing = true
    end
  else
    if %r{^[^\+\-\s@\\]}.match?(line)
      @parsing = false
      return false
    elsif line =~ /^@@ (\+|\-)(\d+)(,\d+)? (\+|\-)(\d+)(,\d+)? @@/
      @line_num_l = $2.to_i
      @line_num_r = $5.to_i
    else
      parse_line(line, @type)
    end
  end
  return true
end

#each_lineObject



64
65
66
67
68
69
70
71
72
# File 'lib/redmine/diff_table.rb', line 64

def each_line
  prev_line_left, prev_line_right = nil, nil
  each do |line|
    spacing = prev_line_left && prev_line_right && (line.nb_line_left != prev_line_left+1) && (line.nb_line_right != prev_line_right+1)
    yield spacing, line
    prev_line_left = line.nb_line_left.to_i if line.nb_line_left.to_i > 0
    prev_line_right = line.nb_line_right.to_i if line.nb_line_right.to_i > 0
  end
end

#inspectObject



74
75
76
77
78
79
80
# File 'lib/redmine/diff_table.rb', line 74

def inspect
  puts '### DIFF TABLE ###'
  puts "file : #{file_name}"
  self.each do |d|
    d.inspect
  end
end