Class: Diff::Combined::Row

Inherits:
Struct
  • Object
show all
Defined in:
lib/diff/combined.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#editsObject

Returns the value of attribute edits

Returns:

  • (Object)

    the current value of edits



6
7
8
# File 'lib/diff/combined.rb', line 6

def edits
  @edits
end

Instance Method Details

#a_linesObject



12
13
14
# File 'lib/diff/combined.rb', line 12

def a_lines
  edits.map { |edit| edit&.a_line }
end

#b_lineObject



16
17
18
# File 'lib/diff/combined.rb', line 16

def b_line
  edits.first&.b_line
end

#to_sObject



20
21
22
23
24
25
26
27
# File 'lib/diff/combined.rb', line 20

def to_s
  symbols = edits.map { |edit| SYMBOLS.fetch(edit&.type, " ") }

  del  = edits.find { |edit| edit&.type == :del }
  line = del ? del.a_line : edits.first.b_line

  symbols.join("") + line.text
end

#typeObject



7
8
9
10
# File 'lib/diff/combined.rb', line 7

def type
  types = edits.compact.map(&:type)
  types.include?(:ins) ? :ins : types.first
end