class SuperDiff::DiffFormatters::MultilineString

Public Class Methods

applies_to?(operation_tree) click to toggle source
# File lib/super_diff/diff_formatters/multiline_string.rb, line 4
def self.applies_to?(operation_tree)
  operation_tree.is_a?(OperationTrees::MultilineString)
end

Public Instance Methods

call() click to toggle source
# File lib/super_diff/diff_formatters/multiline_string.rb, line 8
def call
  lines.join("\n")
end

Private Instance Methods

lines() click to toggle source
# File lib/super_diff/diff_formatters/multiline_string.rb, line 14
def lines
  operation_tree.reduce([]) do |array, operation|
    case operation.name
    when :change
      array << Helpers.style(:expected, "- #{operation.left_value}")
      array << Helpers.style(:actual, "+ #{operation.right_value}")
    when :delete
      array << Helpers.style(:expected, "- #{operation.value}")
    when :insert
      array << Helpers.style(:actual, "+ #{operation.value}")
    else
      array << Helpers.style(:plain, "  #{operation.value}")
    end
  end
end