debian-mirror-gitlab/lib/gitlab/word_diff/segments/diff_hunk.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

45 lines
813 B
Ruby
Raw Normal View History

2021-04-17 20:07:23 +05:30
# frozen_string_literal: true
# Diff hunk is line that starts with @@
# It contains information about start line numbers
#
# Example:
# @@ -1,4 +1,5 @@
#
# See more: https://www.gnu.org/software/diffutils/manual/html_node/Detailed-Unified.html
module Gitlab
module WordDiff
module Segments
class DiffHunk
def initialize(line)
@line = line
end
def pos_old
2022-08-27 11:52:29 +05:30
line.match(/\-[0-9]*/)[0].to_i.abs
rescue StandardError
0
2021-04-17 20:07:23 +05:30
end
def pos_new
2022-08-27 11:52:29 +05:30
line.match(/\+[0-9]*/)[0].to_i.abs
rescue StandardError
0
2021-04-17 20:07:23 +05:30
end
def first_line?
pos_old <= 1 && pos_new <= 1
end
def to_s
line
end
private
attr_reader :line
end
end
end
end