Class: Manifestly::Diff::File
- Inherits:
-
Object
- Object
- Manifestly::Diff::File
- Defined in:
- lib/manifestly/diff.rb
Instance Attribute Summary collapse
-
#from_content ⇒ Object
readonly
Returns the value of attribute from_content.
-
#from_name ⇒ Object
readonly
Returns the value of attribute from_name.
-
#to_content ⇒ Object
readonly
Returns the value of attribute to_content.
-
#to_name ⇒ Object
readonly
Returns the value of attribute to_name.
Instance Method Summary collapse
-
#initialize(file_diff_string) ⇒ File
constructor
A new instance of File.
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_content ⇒ Object (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_name ⇒ Object (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_content ⇒ Object (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_name ⇒ Object (readonly)
Returns the value of attribute to_name.
28 29 30 |
# File 'lib/manifestly/diff.rb', line 28 def to_name @to_name end |