Class: MetaCommit::Models::Line

Inherits:
Object
  • Object
show all
Defined in:
lib/meta_commit/models/line.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#content_offsetObject

Returns the value of attribute content_offset.



3
4
5
# File 'lib/meta_commit/models/line.rb', line 3

def content_offset
  @content_offset
end

#line_originObject

Returns the value of attribute line_origin.



3
4
5
# File 'lib/meta_commit/models/line.rb', line 3

def line_origin
  @line_origin
end

#new_linenoObject

Returns the value of attribute new_lineno.



3
4
5
# File 'lib/meta_commit/models/line.rb', line 3

def new_lineno
  @new_lineno
end

#old_linenoObject

Returns the value of attribute old_lineno.



3
4
5
# File 'lib/meta_commit/models/line.rb', line 3

def old_lineno
  @old_lineno
end

Instance Method Details

#compute_column(old_file_content, new_file_content) ⇒ Numeric, Nil

Compares old_lineno line of old_file_content and new_lineno of new_file_content

Parameters:

  • old_file_content (String)
  • new_file_content (String)

Returns:

  • (Numeric, Nil)

    index of first different symbol in string



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

def compute_column(old_file_content, new_file_content)
  return if old_file_content.empty? || new_file_content.empty?
  return if old_lineno == -1 || new_lineno == -1

  old_file_lines = old_file_content.lines.map(&:chomp)
  old_file_lines = old_file_lines.push('') if old_file_content.end_with?("\n")
  old_line = old_file_lines[old_lineno - 1]

  new_file_lines = new_file_content.lines.map(&:chomp)
  new_file_lines = new_file_lines.push('') if new_file_content.end_with?("\n")
  new_line = new_file_lines[new_lineno - 1]

  return if old_line.empty? || new_line.empty?

  old_line.each_char.with_index do |char, index|
    return index if (char != new_line[index])
  end

  old_line.length
end