Class: UnifiedDiff::Chunk

Inherits:
Object
  • Object
show all
Defined in:
lib/unified_diff/chunk.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ranges) ⇒ Array

Create a new chunk with the specified modified and original ranges

Parameters:

  • A (Hash)

    hash with keys for original and modified line range



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_rangeObject (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_rangeObject (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_linesObject (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_linesArray

Return an array of lines that were added to the original version of the chunk

Returns:

  • (Array)

    the lines that were added to the original



38
39
40
# File 'lib/unified_diff/chunk.rb', line 38

def added_lines
  processed_lines_of_types('+')
end

#modified_linesArray

Return an array of lines that are present in the modified version of the chunk

Returns:

  • (Array)

    the lines 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_linesArray

Return an array of lines that are present in the original version of the chunk

Returns:

  • (Array)

    the lines 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_linesArray

Return an array of lines that were removed from the original version of the chunk

Returns:

  • (Array)

    the lines that were removed from the original



31
32
33
# File 'lib/unified_diff/chunk.rb', line 31

def removed_lines
  processed_lines_of_types('-')
end

#to_sString

Render the chunk as it appeared in the original unified diff

Returns:

  • (String)

    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