Class: DiffMatchPatchES::Patch
- Inherits:
-
Object
- Object
- DiffMatchPatchES::Patch
- Defined in:
- lib/diff_match_patch_es/patch.rb,
sig/diff_match_patch_es/patch.rbs
Overview
One patch operation. start1/start2 are nil until the patch is initialized by patch_make (or parsed by patch_from_text).
Instance Attribute Summary collapse
-
#diffs ⇒ Array[diff]
Returns the value of attribute diffs.
-
#length1 ⇒ Integer
Returns the value of attribute length1.
-
#length2 ⇒ Integer
Returns the value of attribute length2.
-
#start1 ⇒ Integer?
Returns the value of attribute start1.
-
#start2 ⇒ Integer?
Returns the value of attribute start2.
Instance Method Summary collapse
- #==(other) ⇒ Boolean
-
#initialize ⇒ Patch
constructor
A new instance of Patch.
-
#to_s ⇒ String
Emulate GNU diff's format.
Constructor Details
#initialize ⇒ Patch
Returns a new instance of Patch.
8 9 10 11 12 13 14 |
# File 'lib/diff_match_patch_es/patch.rb', line 8 def initialize @diffs = [] @start1 = nil @start2 = nil @length1 = 0 @length2 = 0 end |
Instance Attribute Details
#diffs ⇒ Array[diff]
Returns the value of attribute diffs.
6 7 8 |
# File 'lib/diff_match_patch_es/patch.rb', line 6 def diffs @diffs end |
#length1 ⇒ Integer
Returns the value of attribute length1.
6 7 8 |
# File 'lib/diff_match_patch_es/patch.rb', line 6 def length1 @length1 end |
#length2 ⇒ Integer
Returns the value of attribute length2.
6 7 8 |
# File 'lib/diff_match_patch_es/patch.rb', line 6 def length2 @length2 end |
#start1 ⇒ Integer?
Returns the value of attribute start1.
6 7 8 |
# File 'lib/diff_match_patch_es/patch.rb', line 6 def start1 @start1 end |
#start2 ⇒ Integer?
Returns the value of attribute start2.
6 7 8 |
# File 'lib/diff_match_patch_es/patch.rb', line 6 def start2 @start2 end |
Instance Method Details
#==(other) ⇒ Boolean
48 49 50 51 52 53 54 55 |
# File 'lib/diff_match_patch_es/patch.rb', line 48 def ==(other) other.is_a?(Patch) && diffs == other.diffs && start1 == other.start1 && start2 == other.start2 && length1 == other.length1 && length2 == other.length2 end |
#to_s ⇒ String
Emulate GNU diff's format.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/diff_match_patch_es/patch.rb', line 19 def to_s coords1 = if length1.zero? "#{start1},0" elsif length1 == 1 (start1 + 1).to_s else "#{start1 + 1},#{length1}" end coords2 = if length2.zero? "#{start2},0" elsif length2 == 1 (start2 + 1).to_s else "#{start2 + 1},#{length2}" end text = +"@@ -#{coords1} +#{coords2} @@\n" # Escape the body of the patch with %xx notation. diffs.each do |(op, data)| sign = case op when DIFF_INSERT then '+' when DIFF_DELETE then '-' when DIFF_EQUAL then ' ' end text << sign << JsString.encode_uri(data) << "\n" end text.gsub('%20', ' ') end |