Class: FastHtmlDiff::DiffBuilder
- Inherits:
-
Object
- Object
- FastHtmlDiff::DiffBuilder
- Defined in:
- lib/fast_html_diff.rb
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(html_str_a, html_str_b, config = {}) ⇒ DiffBuilder
constructor
A new instance of DiffBuilder.
Constructor Details
#initialize(html_str_a, html_str_b, config = {}) ⇒ DiffBuilder
Returns a new instance of DiffBuilder.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/fast_html_diff.rb', line 6 def initialize(html_str_a,html_str_b,config={}) @a = html_str_a @b = html_str_b @config = default_config.merge(config) if config[:tokenizer_regexp].nil? if @config[:ignore_punctuation] @config[:tokenizer_regexp] = %r{([^A-Za-z0-9]+)} else @config[:tokenizer_regexp] = %r{(\s+)} end end @word_list = {} @insertions = [] @deletions = [] @split_nodes = Hash.new @insertion_nodes = Hash.new end |
Instance Method Details
#build ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fast_html_diff.rb', line 26 def build # parse, tokenize and index @a = Nokogiri::HTML(@a) @b = Nokogiri::HTML(@b) if @config[:simplify_html] simplify_html(@a) simplify_html(@b) end index_document(@a, :a) index_document(@b, :b) # find the insertions and deletions diff_words # update doc a with tags for the insertions and deletions update_dom @a.to_html end |