class Canon::Diff::DiffLine

Links textual representation to semantic DiffNode and DiffCharRanges
Represents a single line in the diff output

def ==(other)

def ==(other)
  other.is_a?(DiffLine) &&
    line_number == other.line_number &&
    new_position == other.new_position &&
    content == other.content &&
    type == other.type &&
    diff_node == other.diff_node &&
    formatting? == other.formatting?
end

def add_char_range(char_range)

Parameters:
  • char_range (DiffCharRange) --
def add_char_range(char_range)
  @char_ranges << char_range
end

def add_new_char_range(char_range)

Parameters:
  • char_range (DiffCharRange) --
def add_new_char_range(char_range)
  @new_char_ranges << char_range
end

def added?

Returns:
  • (Boolean) - true if this line was added
def added?
  type == :added
end

def changed?

Returns:
  • (Boolean) - true if this line was changed
def changed?
  type == :changed
end

def char_ranges_for_side(side)

Returns:
  • (Array) -

Parameters:
  • side (Symbol) -- :old or :new
def char_ranges_for_side(side)
  side == :old ? @char_ranges : @new_char_ranges
end

def formatting?

Returns:
  • (Boolean) - true if this line represents a formatting-only difference
def formatting?
  @formatting == true
end

def has_char_ranges?

Returns:
  • (Boolean) - true if this line has any character ranges
def has_char_ranges?
  !@char_ranges.empty? || !@new_char_ranges.empty?
end

def informative?

Returns:
  • (Boolean) - true if this line represents an informative-only difference
def informative?
  return false if formatting?
  return false if diff_node.nil?
  diff_node.informative?
end

def initialize(line_number:, content:, type:, diff_node: nil,

Parameters:
  • old_content (String, nil) -- Deprecated: multi-line old content
  • new_content (String, nil) -- The text2 line content (for :changed lines)
  • new_char_ranges (Array) -- Character ranges for text2 side
  • char_ranges (Array) -- Character ranges for text1 side
  • formatting (Boolean) -- Whether this is a formatting-only difference
  • diff_node (DiffNode, nil) -- The semantic diff node this line belongs to
  • type (Symbol) -- The type of line (:unchanged, :added, :removed, :changed)
  • content (String) -- The text content of the line (from text1)
  • new_position (Integer, nil) -- The 0-based line number in text2 (new text),
  • line_number (Integer) -- The 0-based line number in text1 (old text)
def initialize(line_number:, content:, type:, diff_node: nil,
               formatting: false, new_position: nil, old_content: nil,
               char_ranges: nil, new_char_ranges: nil, new_content: nil)
  @line_number = line_number
  @new_position = new_position
  @content = content
  @type = type
  @diff_node = diff_node
  @formatting = formatting
  @old_content = old_content
  @char_ranges = char_ranges || []
  @new_char_ranges = new_char_ranges || []
  @new_content = new_content
end

def normative?

Returns:
  • (Boolean) - true if this line represents a normative difference
def normative?
  return false if formatting?
  return false if diff_node.nil?
  diff_node.normative?
end

def removed?

Returns:
  • (Boolean) - true if this line was removed
def removed?
  type == :removed
end

def to_h

def to_h
  {
    line_number: line_number,
    new_position: new_position,
    content: content,
    new_content: new_content,
    type: type,
    diff_node: diff_node&.to_h,
    normative: normative?,
    informative: informative?,
    formatting: formatting?,
    char_ranges: @char_ranges.map(&:to_h),
    new_char_ranges: @new_char_ranges.map(&:to_h),
  }
end

def unchanged?

Returns:
  • (Boolean) - true if this line is unchanged
def unchanged?
  type == :unchanged
end