class Manifestly::Diff::File
Attributes
from_content[R]
from_name[R]
to_content[R]
to_name[R]
Public Class Methods
new(file_diff_string)
click to toggle source
# File lib/manifestly/diff.rb, line 5 def initialize(file_diff_string) @lines = file_diff_string.split("\n") if content_lines.empty? # if there are no content lines the format of the diff is a little different names = @lines[0].split(' b/') @from_name = names[0][2..-1] # strip "a/" off @to_name = names[1] if file_diff_string.match(/deleted file mode/) @to_name = nil elsif file_diff_string.match(/new file mode/) @from_name = nil end else @from_name = filename(true) @to_name = filename(false) @from_content = content_lines.grep(/^[\- ]/).collect{|l| l[1..-1]}.join("\n") @to_content = content_lines.grep(/^[\+ ]/).collect{|l| l[1..-1]}.join("\n") end end
Protected Instance Methods
content_lines()
click to toggle source
# File lib/manifestly/diff.rb, line 39 def content_lines return @content_lines if @content_lines at_at_line_index = @lines.find_index{|ll| ll[0..2] == "@@ "} @content_lines = at_at_line_index.nil? ? [] : @lines[at_at_line_index+1..-1] end
filename(from)
click to toggle source
# File lib/manifestly/diff.rb, line 32 def filename(from) regex = from ? /^\-\-\- / : /^\+\+\+ / filename = @lines.grep(regex).first[6..-1] filename = nil if filename == "ev/null" filename end