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 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.new("Match block expects one argument") if proc.arity != 1
6
+ raise ArgumentError, "Not enough arguments in block" if proc.arity == 0
7
7
  end
8
8
 
9
- def invoke doc
10
- @proc.call doc
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
@@ -1,3 +1,3 @@
1
1
  module Scrape
2
- VERSION = '0.2.1' unless defined? ::Scrape::VERSION
2
+ VERSION = '0.2.2' unless defined? ::Scrape::VERSION
3
3
  end
@@ -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 the document to the proc" do
18
- doc = "yay"
17
+ test "#invoke should pass 1 argument to proc" do
19
18
  ok = false
20
- match = Scrape::Match.new("test"){|d| ok = (doc == d) }
21
- match.invoke doc
22
- assert ok, "Document was not passed into the proc"
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.1
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 00:00:00.000000000 Z
12
+ date: 2012-07-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri