Class: DiffParser::DiffFilesCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/diff_parser/diff_files_collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(diff, options) ⇒ DiffFilesCollection

Returns a new instance of DiffFilesCollection.



7
8
9
10
# File 'lib/diff_parser/diff_files_collection.rb', line 7

def initialize(diff, options)
  @options = options
  @diff = diff
end

Instance Attribute Details

#diffObject (readonly)

Returns the value of attribute diff.



5
6
7
# File 'lib/diff_parser/diff_files_collection.rb', line 5

def diff
  @diff
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/diff_parser/diff_files_collection.rb', line 5

def options
  @options
end

Instance Method Details

#each {|current_file| ... } ⇒ Object

Yields:

  • (current_file)


16
17
18
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
# File 'lib/diff_parser/diff_files_collection.rb', line 16

def each
  current_file = nil
  file_number = 0

  raw_lines.each_with_index do |raw_line, idx|
    next if raw_line.skip_line?

    if raw_line.info?
      if current_file
        yield current_file
        file_number += 1
      end
      current_file = DiffParser::File.new(raw_line.full_line, diff, file_number)
      current_file.type = raw_lines[idx + 1].type
    elsif fold_file?(current_file)
      if options[:full] == current_file.path || options[:full] == true
        current_file.push_line(raw_line, idx)
      else
        current_file.folded!
        current_file.lines.empty? and (current_file.lines = [DiffLine.new(current_file.path, 'fold', nil, nil, 0, nil)])
      end
    else
      current_file.push_line(raw_line, idx)
    end
  end

  yield current_file unless current_file.nil?
end

#raw_linesObject



12
13
14
# File 'lib/diff_parser/diff_files_collection.rb', line 12

def raw_lines
  diff.raw.lines.map { |line| RawLine.new(line) }
end