Sha256: e59ffb4b143160eae824bf789c879012ca66f76740d2a11066eb199d50bc46a7

Contents?: true

Size: 617 Bytes

Versions: 1

Compression:

Stored size: 617 Bytes

Contents

module Wovnrb
  class TextReplacer < ReplacerBase
    def initialize(text_index)
      @text_index = text_index
    end

    def replace(dom, lang)
      dom.xpath('//text()').each do |node|
        next if wovn_ignore?(node)

        node_text = node.content.strip
        # shouldn't need size check, but for now...
        if @text_index[node_text] && @text_index[node_text][lang.lang_code] && @text_index[node_text][lang.lang_code].size > 0
          node.content = node.content.gsub(/^(\s*)[\S\s]*?(\s*)$/, '\1' + @text_index[node_text][lang.lang_code][0]['data'] + '\2')
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wovnrb-0.2.02 lib/wovnrb/html_replacers/text_replacer.rb