Class: DiffParser::File

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/diff_parser/file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, diff, file_number = 0) ⇒ File

Returns a new instance of File.



9
10
11
12
13
14
15
16
17
# File 'lib/diff_parser/file.rb', line 9

def initialize(path, diff, file_number = 0)
  @path = preprocess_path(path)
  @diff = diff
  @lines = []
  @line_old = 1
  @line_new = 1
  @file_number = file_number
  @file_info = retrieve_file_info(diff)
end

Instance Attribute Details

#diffObject (readonly)

Returns the value of attribute diff.



6
7
8
# File 'lib/diff_parser/file.rb', line 6

def diff
  @diff
end

#file_infoObject (readonly)

Returns the value of attribute file_info.



6
7
8
# File 'lib/diff_parser/file.rb', line 6

def file_info
  @file_info
end

#file_numberObject (readonly)

Returns the value of attribute file_number.



6
7
8
# File 'lib/diff_parser/file.rb', line 6

def file_number
  @file_number
end

#line_newObject

Returns the value of attribute line_new.



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

def line_new
  @line_new
end

#line_oldObject

Returns the value of attribute line_old.



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

def line_old
  @line_old
end

#linesObject

Returns the value of attribute lines.



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

def lines
  @lines
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/diff_parser/file.rb', line 6

def path
  @path
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#file_max_changes_exceeded?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/diff_parser/file.rb', line 53

def file_max_changes_exceeded?
  !file_info || (file_info.changes > DiffParser.max_changes_to_render)
end

#folded!Object



45
46
47
# File 'lib/diff_parser/file.rb', line 45

def folded!
  @folded = true
end

#folded?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/diff_parser/file.rb', line 49

def folded?
  !!@folded
end

#push_line(raw_line, idx) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/diff_parser/file.rb', line 19

def push_line(raw_line, idx)
  if raw_line.type == 'match'
    self.line_old = raw_line.line.match(/\-[0-9]*/)[0].to_i.abs rescue 0
    self.line_new = raw_line.line.match(/\+[0-9]*/)[0].to_i.abs rescue 0

    lines << DiffLine.new(raw_line.full_line, raw_line.type, nil, nil, idx, sha)
  else
    unless raw_line.index?
      lines << DiffLine.new(raw_line.full_line, raw_line.type, line_new, line_old, idx, sha)

      if raw_line.addition?
        self.line_new += 1
      elsif raw_line.deletion?
        self.line_old += 1
      else
        self.line_new += 1
        self.line_old += 1
      end
    end
  end
end

#shaObject



41
42
43
# File 'lib/diff_parser/file.rb', line 41

def sha
  diff.sha
end