Class: Markdown::Merge::ListMatchRefiner

Inherits:
Ast::Merge::MatchRefinerBase
  • Object
show all
Includes:
Ast::Merge::JaccardSimilarity
Defined in:
lib/markdown/merge/list_match_refiner.rb

Overview

Fuzzy matches markdown list nodes by item-token overlap so inner list merging can repair previously-corrupted lists that no longer share an exact signature.

Constant Summary collapse

DEFAULT_THRESHOLD =
0.45

Instance Method Summary collapse

Constructor Details

#initialize(threshold: DEFAULT_THRESHOLD, **options) ⇒ ListMatchRefiner

Returns a new instance of ListMatchRefiner.



12
13
14
# File 'lib/markdown/merge/list_match_refiner.rb', line 12

def initialize(threshold: DEFAULT_THRESHOLD, **options)
  super(threshold: threshold, node_types: [:list], **options)
end

Instance Method Details

#call(template_nodes, dest_nodes, context = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/markdown/merge/list_match_refiner.rb', line 16

def call(template_nodes, dest_nodes, context = {})
  template_lists = template_nodes.select { |node| node_type(node).to_s == 'list' }
  dest_lists = dest_nodes.select { |node| node_type(node).to_s == 'list' }
  return [] if template_lists.empty? || dest_lists.empty?

  greedy_match(template_lists, dest_lists) do |template_node, dest_node|
    compute_similarity(template_node, dest_node, context)
  end
end