Class: Wovnrb::TextReplacer
- Inherits:
-
ReplacerBase
- Object
- ReplacerBase
- Wovnrb::TextReplacer
- Defined in:
- lib/wovnrb/html_replacers/text_replacer.rb
Instance Method Summary collapse
-
#initialize(text_index) ⇒ TextReplacer
constructor
A new instance of TextReplacer.
- #replace(dom, lang) ⇒ Object
Constructor Details
#initialize(text_index) ⇒ TextReplacer
Returns a new instance of TextReplacer.
3 4 5 |
# File 'lib/wovnrb/html_replacers/text_replacer.rb', line 3 def initialize(text_index) @text_index = text_index end |
Instance Method Details
#replace(dom, lang) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/wovnrb/html_replacers/text_replacer.rb', line 7 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 add_comment_node(node, node_text) node.content = replace_text(node.content, @text_index[node_text][lang.lang_code][0]['data']) end end end |