Class: Titi::Matcher::MatchFirstElement

Inherits:
Base
  • Object
show all
Defined in:
lib/titi/matcher.rb

Direct Known Subclasses

MatchProc

Instance Attribute Summary

Attributes inherited from Base

#matcher, #selector

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Titi::Matcher::Base

Instance Method Details

#match(doc) ⇒ Object

return the inner_html of the given element

eg.

m = MatchFirstElement.new('span#bio/a.homepage')
m.match('<span id="bio"><a class="homepage" href="http://foo.bar">My Homepage</a></span>')
# => 'My Homepage'


23
24
25
26
# File 'lib/titi/matcher.rb', line 23

def match doc
  el = doc.at(selector) or return nil
  matcher ? matcher.match(el) : el.inner_html
end