Class: Motion::HTML::Doc

Inherits:
Object
  • Object
show all
Defined in:
lib/project/motion-html.rb

Instance Method Summary collapse

Constructor Details

#initialize(html) ⇒ Doc

Returns a new instance of Doc.



8
9
10
# File 'lib/project/motion-html.rb', line 8

def initialize(html)
  @doc = IGHTMLDocument.alloc.initWithHTMLString(html, error: nil)
end

Instance Method Details

#query(q) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/project/motion-html.rb', line 12

def query(q)
  if q =~ %r{^[//|/]}
    node_set = @doc.queryWithXPath(q)
  else
    node_set = @doc.queryWithCSS(q)
  end
  nodes = []
  node_set.enumerateNodesUsingBlock -> (node, index, stop) { nodes << node }
  nodes
end