2014-09-08 09:25:50 -04:00
|
|
|
module Gitlab
|
|
|
|
module Diff
|
|
|
|
class Line
|
2015-12-30 18:42:11 -05:00
|
|
|
attr_reader :type, :index, :old_pos, :new_pos
|
|
|
|
attr_accessor :text
|
2014-09-08 09:25:50 -04:00
|
|
|
|
2014-09-08 14:54:52 -04:00
|
|
|
def initialize(text, type, index, old_pos, new_pos)
|
|
|
|
@text, @type, @index = text, type, index
|
2014-09-08 09:25:50 -04:00
|
|
|
@old_pos, @new_pos = old_pos, new_pos
|
|
|
|
end
|
2015-10-01 07:52:08 -04:00
|
|
|
|
2016-06-20 13:15:44 -04:00
|
|
|
def old_line
|
|
|
|
old_pos unless added? || meta?
|
|
|
|
end
|
|
|
|
|
|
|
|
def new_line
|
|
|
|
new_pos unless removed? || meta?
|
|
|
|
end
|
|
|
|
|
|
|
|
def unchanged?
|
|
|
|
type.nil?
|
|
|
|
end
|
|
|
|
|
2015-10-01 07:52:08 -04:00
|
|
|
def added?
|
|
|
|
type == 'new'
|
|
|
|
end
|
|
|
|
|
|
|
|
def removed?
|
|
|
|
type == 'old'
|
|
|
|
end
|
2016-06-20 13:15:44 -04:00
|
|
|
|
|
|
|
def meta?
|
|
|
|
type == 'match' || type == 'nonewline'
|
|
|
|
end
|
2014-09-08 09:25:50 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|