scrape 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/scrape/match.rb +4 -3
- data/lib/scrape/site.rb +1 -1
- data/lib/scrape/version.rb +1 -1
- data/test/unit/match_test.rb +18 -5
- metadata +2 -2
data/lib/scrape/match.rb
CHANGED
@@ -3,11 +3,12 @@ class Scrape::Match
|
|
3
3
|
|
4
4
|
def initialize matcher, &proc
|
5
5
|
@matcher, @proc = matcher, proc
|
6
|
-
raise ArgumentError
|
6
|
+
raise ArgumentError, "Not enough arguments in block" if proc.arity == 0
|
7
7
|
end
|
8
8
|
|
9
|
-
def invoke
|
10
|
-
@proc.
|
9
|
+
def invoke *args
|
10
|
+
args = args[0, @proc.arity] unless @proc.arity == -1
|
11
|
+
@proc.call *args
|
11
12
|
end
|
12
13
|
|
13
14
|
def =~ url
|
data/lib/scrape/site.rb
CHANGED
@@ -23,7 +23,7 @@ class Scrape::Site
|
|
23
23
|
url = normalize url
|
24
24
|
doc = Nokogiri::HTML Scrape.open(url)
|
25
25
|
|
26
|
-
@matches.each{|match| match.invoke doc if match =~ url }
|
26
|
+
@matches.each{|match| match.invoke doc, url if match =~ url }
|
27
27
|
|
28
28
|
doc.css("a[href]").map{|node| normalize node['href'], url }.select{|url| accept? url }
|
29
29
|
end
|
data/lib/scrape/version.rb
CHANGED
data/test/unit/match_test.rb
CHANGED
@@ -14,12 +14,25 @@ class MatchTest < Scrape::TestCase
|
|
14
14
|
assert ok, "Proc was not called"
|
15
15
|
end
|
16
16
|
|
17
|
-
test "#invoke should pass
|
18
|
-
doc = "yay"
|
17
|
+
test "#invoke should pass 1 argument to proc" do
|
19
18
|
ok = false
|
20
|
-
match = Scrape::Match.new("test"){|
|
21
|
-
match.invoke
|
22
|
-
assert ok, "
|
19
|
+
match = Scrape::Match.new("test"){|one| ok = (one == "foo") }
|
20
|
+
match.invoke "foo"
|
21
|
+
assert ok, "Expected 1 argument to be passed"
|
22
|
+
end
|
23
|
+
|
24
|
+
test "#invoke should pass 2 arguments to proc" do
|
25
|
+
ok = false
|
26
|
+
match = Scrape::Match.new("test"){|one, two| ok = (one == "foo" && two == "bar") }
|
27
|
+
match.invoke "foo", "bar"
|
28
|
+
assert ok, "Expected 2 arguments to be passed"
|
29
|
+
end
|
30
|
+
|
31
|
+
test "#invoke should pass all arguments to proc" do
|
32
|
+
ok = false
|
33
|
+
match = Scrape::Match.new("test"){|*args| ok = (args == ["foo", "bar"]) }
|
34
|
+
match.invoke "foo", "bar"
|
35
|
+
assert ok, "Expected 2 arguments to be passed"
|
23
36
|
end
|
24
37
|
|
25
38
|
test "#=~ should return true when contains string" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scrape
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|