Class: Diffed::UnifiedDiffParser::HeaderLineParser

Inherits:
Object
  • Object
show all
Defined in:
lib/parsers/unified.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line) ⇒ HeaderLineParser

Returns a new instance of HeaderLineParser.



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/parsers/unified.rb', line 102

def initialize(line)
  @text = line

  if line =~ /^@@ -(\d+),(\d+) \+(\d+),(\d+) @@/        
    @line_nums = {left: {from: $1.to_i, lines: $2.to_i}, right: {from: $3.to_i, lines: $4.to_i}}
  elsif line =~ /^@@ -(\d+) \+(\d+) @@/
    @line_nums = {left: {from: $1.to_i, lines: $1.to_i}, right: {from: $2.to_i, lines: $2.to_i}}
  else
    raise "Unparseable header line: #{line}"
  end

  if @line_nums[:right][:lines] > @line_nums[:left][:lines]
    @side_to_count = :right
  else
    @side_to_count = :left
  end      
end

Instance Attribute Details

#line_numsObject (readonly)

Returns the value of attribute line_nums.



100
101
102
# File 'lib/parsers/unified.rb', line 100

def line_nums
  @line_nums
end

#textObject (readonly)

Returns the value of attribute text.



100
101
102
# File 'lib/parsers/unified.rb', line 100

def text
  @text
end

Class Method Details

.is_header?(line) ⇒ Boolean

Returns:

  • (Boolean)


120
121
122
# File 'lib/parsers/unified.rb', line 120

def self.is_header?(line)
  line.start_with? "@@ "
end

Instance Method Details

#lineObject



128
129
130
# File 'lib/parsers/unified.rb', line 128

def line
  @text
end

#section_complete?(left_count, right_count) ⇒ Boolean

Returns:

  • (Boolean)


124
125
126
# File 'lib/parsers/unified.rb', line 124

def section_complete?(left_count, right_count)
  left_count >= @line_nums[:left][:lines] && right_count >= @line_nums[:right][:lines]
end