Class: Oga::XML::Document
- Inherits:
-
Object
- Object
- Oga::XML::Document
- Defined in:
- lib/monkey_patch/oga_document.rb
Instance Method Summary collapse
- #html_node ⇒ Object
- #interlace(other, level:) ⇒ Object
- #lang ⇒ Object
-
#lang=(lang) ⇒ Object
TODO: handle non-HTML.
Instance Method Details
#html_node ⇒ Object
20 21 22 |
# File 'lib/monkey_patch/oga_document.rb', line 20 def html_node at_xpath('html') end |
#interlace(other, level:) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/monkey_patch/oga_document.rb', line 36 def interlace(other, level:) nodes = css(level).to_a nodes_other = other.css(level).to_a root_lang = lang root_lang_other = other.lang nodes.each.with_index do |node, i| node_other = nodes_other[i] node.lang = root_lang node_other.lang = root_lang_other next if node.text() == nodes_other[i].text() node.after(node_other) end end |
#lang ⇒ Object
24 25 26 |
# File 'lib/monkey_patch/oga_document.rb', line 24 def lang html_node&.lang end |
#lang=(lang) ⇒ Object
TODO: handle non-HTML
29 30 31 |
# File 'lib/monkey_patch/oga_document.rb', line 29 def lang=(lang) html_node&.lang = lang end |