class Grit::DiffHunk

Attributes

lines[R]

Public Class Methods

new(header, diff_hunk) click to toggle source
# File lib/grit/ext/diff_hunk.rb, line 5
def initialize(header, diff_hunk)
  @header = header
  @lines = []

  diff_hunk.each_with_index.map do |line, index|
    content = line[1..line.length - 1]
    status = DiffLine.status_from_char(line[0])

    if status
      line_number = header.start + index

      case status
      when :added, :unchanged
        line_number = line_number - removed.count
      when :removed
        line_number = line_number - added.count
      end

      @lines << DiffLine.new(content, status, line_number, index)
    end
  end.compact
end

Public Instance Methods

added() click to toggle source
# File lib/grit/ext/diff_hunk.rb, line 28
def added
  @lines.find_all { |line| line.added? }
end
removed() click to toggle source
# File lib/grit/ext/diff_hunk.rb, line 32
def removed
  @lines.find_all { |line| line.removed? }
end
to_s() click to toggle source
# File lib/grit/ext/diff_hunk.rb, line 40
def to_s
  "#{@header}\n#{lines.join("\n")}"
end
unchanged() click to toggle source
# File lib/grit/ext/diff_hunk.rb, line 36
def unchanged
  @lines.find_all { |line| line.unchanged? }
end