Class: Wovnrb::InputReplacer
- Inherits:
-
ReplacerBase
- Object
- ReplacerBase
- Wovnrb::InputReplacer
- Defined in:
- lib/wovnrb/html_replacers/input_replacer.rb
Instance Method Summary collapse
-
#initialize(text_index) ⇒ InputReplacer
constructor
A new instance of InputReplacer.
- #replace(dom, lang) ⇒ Object
Constructor Details
#initialize(text_index) ⇒ InputReplacer
Returns a new instance of InputReplacer.
3 4 5 |
# File 'lib/wovnrb/html_replacers/input_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 19 20 21 22 23 24 25 |
# File 'lib/wovnrb/html_replacers/input_replacer.rb', line 7 def replace(dom, lang) dom.xpath('//input').select { |node| next if wovn_ignore?(node) (node.get_attribute('value') && node.get_attribute('value') != '' && node.get_attribute('type') && node.get_attribute('type') != 'text' && node.get_attribute('type') != 'hidden' && node.get_attribute('type') != 'password' && node.get_attribute('type') != 'url' && node.get_attribute('type') != 'search') }.each do |node| node_value = node.get_attribute('value').strip # shouldn't need size check, but for now... if @text_index[node_value] && @text_index[node_value][lang.lang_code] && @text_index[node_value][lang.lang_code].size > 0 node.set_attribute('value', replace_text(node.get_attribute('value'), @text_index[node_value][lang.lang_code][0]['data'])) end end end |