Welcome to mirror list, hosted at ThFree Co, Russian Federation.

diff_hunk.rb « segments « word_diff « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 13f71f2bc0491fb18ba5d296966aab5642c53667 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# 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
          line.match(/\-[0-9]*/)[0].to_i.abs
        rescue StandardError
          0
        end

        def pos_new
          line.match(/\+[0-9]*/)[0].to_i.abs
        rescue StandardError
          0
        end

        def first_line?
          pos_old <= 1 && pos_new <= 1
        end

        def to_s
          line
        end

        private

        attr_reader :line
      end
    end
  end
end