Class: Diffed::UnifiedDiffParser

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

Defined Under Namespace

Classes: HeaderLineParser, LineParser

Instance Method Summary collapse

Constructor Details

#initialize(lines) ⇒ UnifiedDiffParser

Returns a new instance of UnifiedDiffParser.



6
7
8
9
# File 'lib/parsers/unified.rb', line 6

def initialize(lines)
  @lines, @sections = lines, []
  reset_section!
end

Instance Method Details

#parse!Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/parsers/unified.rb', line 11

def parse!
  raise "Already parsed into #{@sections.length} sections." unless @sections.empty?
  
  @lines.each do |line|
    if HeaderLineParser.is_header?(line)
      @curr_header, @curr_lines = HeaderLineParser.new(line), []
    elsif @curr_header.nil?
      # Do nothing.  We haven't started yet.
      # puts "Ignoring line: #{line}"
    elsif line =~ /\\ No newline at end of file/
      handle_missing_newline
    else
      parse_code_line line
    end
  end      
  
  self # evidence that I'm a Java developer at heart?
end

#sectionsObject



30
31
32
# File 'lib/parsers/unified.rb', line 30

def sections
  @sections
end