Class: Redmine::DiffTable
Overview
Class that represents a file diff
Instance Attribute Summary (collapse)
-
- (Object) file_name
readonly
Returns the value of attribute file_name.
Instance Method Summary (collapse)
-
- (Object) add_line(line)
Function for add a line of this Diff Returns false when the diff ends.
- - (Object) each_line
-
- (DiffTable) initialize(type = "inline")
constructor
Initialize with a Diff file and the type of Diff View The type view must be inline or sbs (side_by_side).
- - (Object) inspect
Methods included from Diffable
#diff, #patch, #replacenextlarger, #reverse_hash
Constructor Details
- (DiffTable) initialize(type = "inline")
Initialize with a Diff file and the type of Diff View The type view must be inline or sbs (side_by_side)
60 61 62 63 64 65 |
# File 'lib/redmine/unified_diff.rb', line 60 def initialize(type="inline") @parsing = false @added = 0 @removed = 0 @type = type end |
Instance Attribute Details
- (Object) file_name (readonly)
Returns the value of attribute file_name
56 57 58 |
# File 'lib/redmine/unified_diff.rb', line 56 def file_name @file_name end |
Instance Method Details
- (Object) add_line(line)
Function for add a line of this Diff Returns false when the diff ends
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/redmine/unified_diff.rb', line 69 def add_line(line) unless @parsing if line =~ /^(---|\+\+\+) (.*)$/ @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 line =~ /^[^\+\-\s@\\]/ @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 |
- (Object) each_line
92 93 94 95 96 97 98 99 100 |
# File 'lib/redmine/unified_diff.rb', line 92 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 |
- (Object) inspect
102 103 104 105 106 107 108 |
# File 'lib/redmine/unified_diff.rb', line 102 def inspect puts '### DIFF TABLE ###' puts "file : #{file_name}" self.each do |d| d.inspect end end |