Class: Wovnrb::MetaReplacer
- Inherits:
-
ReplacerBase
- Object
- ReplacerBase
- Wovnrb::MetaReplacer
- Defined in:
- lib/wovnrb/html_replacers/meta_replacer.rb
Instance Method Summary collapse
-
#initialize(text_index) ⇒ MetaReplacer
constructor
A new instance of MetaReplacer.
- #replace(dom, lang) ⇒ Object
Constructor Details
#initialize(text_index) ⇒ MetaReplacer
Returns a new instance of MetaReplacer.
3 4 5 |
# File 'lib/wovnrb/html_replacers/meta_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/meta_replacer.rb', line 7 def replace(dom, lang) dom.xpath('//meta').select { |node| next if wovn_ignore?(node) (node.get_attribute('name') || node.get_attribute('property') || '') =~ /^(description|title|og:title|og:description|twitter:title|twitter:description)$/ }.each do |node| node_content = node.get_attribute('content').strip # shouldn't need size check, but for now... if @text_index[node_content] && @text_index[node_content][lang.lang_code] && @text_index[node_content][lang.lang_code].size > 0 node.set_attribute('content', replace_text(node.get_attribute('content'), @text_index[node_content][lang.lang_code][0]['data'])) end end end |