summaryrefslogtreecommitdiff
path: root/lib/gitlab/word_diff/segments/chunk.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/word_diff/segments/chunk.rb')
-rw-r--r--lib/gitlab/word_diff/segments/chunk.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/gitlab/word_diff/segments/chunk.rb b/lib/gitlab/word_diff/segments/chunk.rb
new file mode 100644
index 00000000000..7c5850666f9
--- /dev/null
+++ b/lib/gitlab/word_diff/segments/chunk.rb
@@ -0,0 +1,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