Class: Wovnrb::LinkReplacer
- Inherits:
-
ReplacerBase
- Object
- ReplacerBase
- Wovnrb::LinkReplacer
- Defined in:
- lib/wovnrb/html_replacers/link_replacer.rb
Instance Method Summary collapse
-
#initialize(pattern, headers) ⇒ LinkReplacer
constructor
A new instance of LinkReplacer.
- #replace(dom, lang) ⇒ Object
Constructor Details
#initialize(pattern, headers) ⇒ LinkReplacer
Returns a new instance of LinkReplacer.
3 4 5 6 |
# File 'lib/wovnrb/html_replacers/link_replacer.rb', line 3 def initialize(pattern, headers) @pattern = pattern @headers = headers end |
Instance Method Details
#replace(dom, lang) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/wovnrb/html_replacers/link_replacer.rb', line 8 def replace(dom, lang) dom.xpath('//a').each do |node| next if wovn_ignore?(node) href = node.get_attribute('href') next if href =~ /^\s*\{\{.+\}\}\s*$/ next if href =~ /javascript:void\(/ new_href = lang.add_lang_code(href, @pattern, @headers) node.set_attribute('href', new_href) end end |