Sha256: 4091a7cfbfcfab187751ae858b4a8a2344610b930bf9b093e69f3e93f8557f02
Contents?: true
Size: 1.23 KB
Versions: 6
Compression:
Stored size: 1.23 KB
Contents
# # Represent a single piece of a diff. # class PrettyDiff::Chunk #:nodoc: attr_reader :diff, :meta_info, :input, :lines def initialize(diff, meta_info, input) @diff = diff @meta_info = meta_info @input = input end # Generate HTML presentation for a Chunk. Return a string. def to_html # We have to find lines before we can call line numbers methods. find_lines! generator.generate end # Return LineNumbers object that represents two columns of numbers # that will be displayed on the left of the HTML presentation. # # IMPORTANT! Before calling this method it's essential to call "find_lines!" first, # otherwise the array will be empty. def line_numbers @_line_numbers ||= PrettyDiff::LineNumbers.new(diff, meta_info) end private def generator @_generator ||= PrettyDiff::ChunkGenerator.new(self) end # Parse the input searching for lines. Initialize Line object for every line. # Return an array of Line objects. def find_lines! @lines = [] @lines.tap do input.split(/\r?\n/).each do |line_str| line = PrettyDiff::Line.new(diff, line_str) next if line.ignore? @lines << line line_numbers.act_on_line(line) end end end end
Version data entries
6 entries across 6 versions & 1 rubygems