Top Level Namespace
Defined Under Namespace
Classes: CParsley, Parsley, ParsleyError
Constant Summary
collapse
- EXT =
File.expand_path(File.dirname(__FILE__))
- LIBDIR =
Config::CONFIG['libdir']
- INCLUDEDIR =
Config::CONFIG['includedir']
- YELP_HTML =
File.dirname(__FILE__) + "/yelp.html"
Instance Method Summary
collapse
Instance Method Details
#hpri ⇒ Object
14
15
16
|
# File 'ext/parsley/test/yelp-benchmark.rb', line 14
def hpri
parse Hpricot(File.open(YELP_HTML))
end
|
#noko ⇒ Object
10
11
12
|
# File 'ext/parsley/test/yelp-benchmark.rb', line 10
def noko
parse Nokogiri.Hpricot(File.open(YELP_HTML))
end
|
#pars ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'ext/parsley/test/yelp-benchmark.rb', line 32
def pars
parselet = Parsley.new({
"name" => "h1",
"phone" => "#bizPhone",
"address" => "address",
"reviews(.nonfavoriteReview)" => [
{
"date" => ".ieSucks .smaller",
"user_name" => ".reviewer_info a",
"comment" => ".review_comment"
}
]
})
parselet.parse(:file => YELP_HTML)
end
|
#parse(doc) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'ext/parsley/test/yelp-benchmark.rb', line 18
def parse(doc)
out = {}
out["name"] = (doc / "h1").first.inner_text
out["phone"] = (doc / "#bizPhone").first.inner_text
out["address"] = (doc / "address").first.inner_text
out["reviews"] = (doc / ".nonfavoriteReview").map do |node|
review = {}
review["date"] = (node / ".ieSucks .smaller").first.inner_text
review["user_name"] = (node / ".reviewer_info a").first.inner_text
review["comment"] = (node / ".review_comment").first.inner_text
review
end
end
|