Class: Docsmith::Diff::Engine

Inherits:
Object
  • Object
show all
Defined in:
lib/docsmith/diff/engine.rb

Overview

Computes diffs between two DocumentVersion records. For markdown and html content types, a format-aware parser is used (word-level for markdown, tag-atomic for html). Falls back to Renderers::Base (line-level) for json and unknown types.

Constant Summary collapse

PARSERS =
{
  "markdown" => Parsers::Markdown,
  "html"     => Parsers::Html
}.freeze

Class Method Summary collapse

Class Method Details

.between(version_a, version_b) ⇒ Docsmith::Diff::Result

Parameters:

Returns:



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/docsmith/diff/engine.rb', line 19

def between(version_a, version_b)
  content_type = version_a.content_type.to_s
  parser       = PARSERS.fetch(content_type, Renderers::Base).new
  changes      = parser.compute(version_a.content.to_s, version_b.content.to_s)

  Result.new(
    content_type: content_type,
    from_version: version_a.version_number,
    to_version:   version_b.version_number,
    changes:      changes
  )
end