Class: Manifestly::Diff::File

Inherits:
Object
  • Object
show all
Defined in:
lib/manifestly/diff.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_diff_string) ⇒ File

Returns a new instance of File.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 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

Instance Attribute Details

#from_contentObject (readonly)

Returns the value of attribute from_content.



28
29
30
# File 'lib/manifestly/diff.rb', line 28

def from_content
  @from_content
end

#from_nameObject (readonly)

Returns the value of attribute from_name.



28
29
30
# File 'lib/manifestly/diff.rb', line 28

def from_name
  @from_name
end

#to_contentObject (readonly)

Returns the value of attribute to_content.



28
29
30
# File 'lib/manifestly/diff.rb', line 28

def to_content
  @to_content
end

#to_nameObject (readonly)

Returns the value of attribute to_name.



28
29
30
# File 'lib/manifestly/diff.rb', line 28

def to_name
  @to_name
end