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

chunk.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: 7c5850666f9895143c768cfccad6af92360d3d55 (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
# frozen_string_literal: true

# Chunk is a part of the line that starts with ` `, `-`, `+`
# Consecutive chunks build a line. Line that starts with `~` is an identifier of
# end of the line.
module Gitlab
  module WordDiff
    module Segments
      class Chunk
        def initialize(line)
          @line = line
        end

        def removed?
          line[0] == '-'
        end

        def added?
          line[0] == '+'
        end

        def to_s
          line[1..] || ''
        end

        def length
          to_s.length
        end

        private

        attr_reader :line
      end
    end
  end
end