Class: UnifiedDiff::Chunk
- Inherits:
-
Object
- Object
- UnifiedDiff::Chunk
- Defined in:
- lib/unified_diff/chunk.rb
Instance Attribute Summary collapse
-
#modified_range ⇒ Object
readonly
Returns the value of attribute modified_range.
-
#original_range ⇒ Object
readonly
Returns the value of attribute original_range.
-
#raw_lines ⇒ Object
readonly
Returns the value of attribute raw_lines.
Instance Method Summary collapse
-
#added_lines ⇒ Array
Return an array of lines that were added to the original version of the chunk.
-
#initialize(ranges) ⇒ Array
constructor
Create a new chunk with the specified modified and original ranges.
-
#modified_lines ⇒ Array
Return an array of lines that are present in the modified version of the chunk.
-
#original_lines ⇒ Array
Return an array of lines that are present in the original version of the chunk.
-
#removed_lines ⇒ Array
Return an array of lines that were removed from the original version of the chunk.
-
#to_s ⇒ String
Render the chunk as it appeared in the original unified diff.
Constructor Details
#initialize(ranges) ⇒ Array
Create a new chunk with the specified modified and original ranges
9 10 11 12 13 |
# File 'lib/unified_diff/chunk.rb', line 9 def initialize(ranges) @original_range = ranges[:original] @modified_range = ranges[:modified] @raw_lines = [] end |
Instance Attribute Details
#modified_range ⇒ Object (readonly)
Returns the value of attribute modified_range.
3 4 5 |
# File 'lib/unified_diff/chunk.rb', line 3 def modified_range @modified_range end |
#original_range ⇒ Object (readonly)
Returns the value of attribute original_range.
3 4 5 |
# File 'lib/unified_diff/chunk.rb', line 3 def original_range @original_range end |
#raw_lines ⇒ Object (readonly)
Returns the value of attribute raw_lines.
3 4 5 |
# File 'lib/unified_diff/chunk.rb', line 3 def raw_lines @raw_lines end |
Instance Method Details
#added_lines ⇒ Array
Return an array of lines that were added to the original version of the chunk
38 39 40 |
# File 'lib/unified_diff/chunk.rb', line 38 def added_lines processed_lines_of_types('+') end |
#modified_lines ⇒ Array
Return an array of lines that are present in the modified version of the chunk
45 46 47 |
# File 'lib/unified_diff/chunk.rb', line 45 def modified_lines processed_lines_of_types(' ','+') end |
#original_lines ⇒ Array
Return an array of lines that are present in the original version of the chunk
52 53 54 |
# File 'lib/unified_diff/chunk.rb', line 52 def original_lines processed_lines_of_types(' ','-') end |
#removed_lines ⇒ Array
Return an array of lines that were removed from the original version of the chunk
31 32 33 |
# File 'lib/unified_diff/chunk.rb', line 31 def removed_lines processed_lines_of_types('-') end |
#to_s ⇒ String
Render the chunk as it appeared in the original unified diff
19 20 21 22 23 24 25 26 |
# File 'lib/unified_diff/chunk.rb', line 19 def to_s "@@ "+ "-#{@original_range.begin},#{@original_range.count} " + "+#{@modified_range.begin},#{@modified_range.count} " + "@@\n" + @raw_lines.join("\n") + "\n" end |