Class: Integrity::Notifier::Test::HpricotMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/integrity/notifier/test/hpricot_matcher.rb

Overview

Thanks Harry! gist.github.com/39960

Instance Method Summary collapse

Constructor Details

#initialize(html) ⇒ HpricotMatcher

Returns a new instance of HpricotMatcher.



8
9
10
# File 'lib/integrity/notifier/test/hpricot_matcher.rb', line 8

def initialize(html)
  @doc = Hpricot(html)
end

Instance Method Details

#element(selector) ⇒ Object

element(‘h1’) returns Hpricot::Elem with first h1-tag, or nil if none exist.



19
20
21
# File 'lib/integrity/notifier/test/hpricot_matcher.rb', line 19

def element(selector)
  @doc.at(selector)
end

#elements(selector) ⇒ Object

elements(‘h1’) returns a Hpricot::Elements object with all h1-tags.



13
14
15
# File 'lib/integrity/notifier/test/hpricot_matcher.rb', line 13

def elements(selector)
  @doc.search(selector)
end

#tag(selector) ⇒ Object

tag(‘h1’) returns the inner HTML of the first mached element, or nil if none matched.



31
32
33
34
# File 'lib/integrity/notifier/test/hpricot_matcher.rb', line 31

def tag(selector)
  e = element(selector)
  e && e.inner_html
end

#tags(selector) ⇒ Object

tags(‘h1’) returns the inner HTML of all matched elements mathed.



24
25
26
27
# File 'lib/integrity/notifier/test/hpricot_matcher.rb', line 24

def tags(selector)
  e = elements(selector)
  e.map {|x| x.inner_html}
end