Class: UnifiedDiff::Diff
- Inherits:
-
Object
- Object
- UnifiedDiff::Diff
- Defined in:
- lib/unified_diff/diff.rb
Defined Under Namespace
Classes: UnifiedDiffException
Constant Summary collapse
- FILE_PATTERN =
/([^\t\n]+)(?:\t'{2}?([^']+)'{2}?)?/
- OLD_FILE_PATTERN =
/--- #{FILE_PATTERN}/
- NEW_FILE_PATTERN =
/\+\+\+ #{FILE_PATTERN}/
- CHUNK_PATTERN =
Match assignment is tricky for CHUNK_PATTERN $1 and $3 are static, but $2 and $4 can be nil
“In many versions of GNU diff, each range can omit the comma and
trailing value s, in which case s defaults to 1. Note that the only really interesting value is the l line number of the first range; all the other values can be computed from the diff." -- http://en.wikipedia.org/wiki/Diff#Unified_format
Pattern -W,X Y,Z has $1 = W, $2 = X, $3 = Y, $4 = Z Pattern -W Y,Z has $1 = W, $2 = nil, $3 = Y, $4 = Z Pattern -W Y has $1 = W, $2 = nil, $3 = Y, $4 = nil Pattern -W,X Y has $1 = W, $2 = X, $3 = Y, $4 = nil
/^@@\s+-(\d+)(?:,(\d+))?\s+\+(\d+)(?:,(\d+))?\s+@@/
- ADDED_PATTERN =
/^\+(.*)/
- REMOVED_PATTERN =
/^-(.*)/
- UNCHANGED_PATTERN =
/^ (.*)/
- NO_NEWLINE_PATTERN =
/^\\(\s+No\s+newline\s+at\s+end\s+of\s+file)$/
Instance Attribute Summary collapse
-
#chunks ⇒ Object
readonly
Returns the value of attribute chunks.
-
#modified_file ⇒ Object
readonly
Returns the value of attribute modified_file.
-
#modified_timestamp ⇒ Object
readonly
Returns the value of attribute modified_timestamp.
-
#original ⇒ Object
readonly
Returns the value of attribute original.
-
#original_file ⇒ Object
readonly
Returns the value of attribute original_file.
-
#original_timestamp ⇒ Object
readonly
Returns the value of attribute original_timestamp.
Instance Method Summary collapse
-
#initialize(diff) ⇒ Diff
constructor
Create and parse a unified diff.
-
#to_s ⇒ String
Render the diff as it appeared originally.
Constructor Details
#initialize(diff) ⇒ Diff
Create and parse a unified diff
33 34 35 36 |
# File 'lib/unified_diff/diff.rb', line 33 def initialize(diff) @original = diff parse end |
Instance Attribute Details
#chunks ⇒ Object (readonly)
Returns the value of attribute chunks.
4 5 6 |
# File 'lib/unified_diff/diff.rb', line 4 def chunks @chunks end |
#modified_file ⇒ Object (readonly)
Returns the value of attribute modified_file.
4 5 6 |
# File 'lib/unified_diff/diff.rb', line 4 def modified_file @modified_file end |
#modified_timestamp ⇒ Object (readonly)
Returns the value of attribute modified_timestamp.
4 5 6 |
# File 'lib/unified_diff/diff.rb', line 4 def @modified_timestamp end |
#original ⇒ Object (readonly)
Returns the value of attribute original.
4 5 6 |
# File 'lib/unified_diff/diff.rb', line 4 def original @original end |
#original_file ⇒ Object (readonly)
Returns the value of attribute original_file.
4 5 6 |
# File 'lib/unified_diff/diff.rb', line 4 def original_file @original_file end |
#original_timestamp ⇒ Object (readonly)
Returns the value of attribute original_timestamp.
4 5 6 |
# File 'lib/unified_diff/diff.rb', line 4 def @original_timestamp end |
Instance Method Details
#to_s ⇒ String
Render the diff as it appeared originally
41 42 43 |
# File 'lib/unified_diff/diff.rb', line 41 def to_s @original end |