product_spy 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/product_spy/host.rb +11 -5
- data/lib/product_spy/version.rb +1 -1
- data/spec/host_spec.rb +27 -0
- metadata +2 -2
data/lib/product_spy/host.rb
CHANGED
@@ -18,13 +18,18 @@ module ProductSpy
|
|
18
18
|
end
|
19
19
|
|
20
20
|
class Builder
|
21
|
-
def initialize(pattern)
|
21
|
+
def initialize(pattern, &block)
|
22
22
|
@pattern = pattern
|
23
|
+
@block = block
|
23
24
|
end
|
24
25
|
|
25
26
|
def get_url(pk)
|
26
|
-
@
|
27
|
-
pk
|
27
|
+
if @block.respond_to?(:call)
|
28
|
+
@block.call(pk)
|
29
|
+
else
|
30
|
+
@pattern.gsub /:(\d+)/ do |i|
|
31
|
+
pk[i[1..-1].to_i-1]
|
32
|
+
end
|
28
33
|
end
|
29
34
|
end
|
30
35
|
end
|
@@ -41,8 +46,9 @@ module ProductSpy
|
|
41
46
|
@parser << Parser.new(regex, pk_keys)
|
42
47
|
end
|
43
48
|
|
44
|
-
def build(type, pattern)
|
45
|
-
|
49
|
+
def build(type, pattern = nil, &block)
|
50
|
+
raise "No pattern and no block given" if pattern.nil? and not block_given?
|
51
|
+
@builder[type.to_sym] = Builder.new(pattern, &block)
|
46
52
|
end
|
47
53
|
|
48
54
|
def make_url(pk, options)
|
data/lib/product_spy/version.rb
CHANGED
data/spec/host_spec.rb
CHANGED
@@ -6,4 +6,31 @@ describe ProductSpy::Host do
|
|
6
6
|
host.make_pk('http://amazon.de/whatever').should be_nil
|
7
7
|
end
|
8
8
|
end
|
9
|
+
|
10
|
+
describe '#build' do
|
11
|
+
it 'accepts a block in configuration' do
|
12
|
+
ProductSpy.setup do |config|
|
13
|
+
config.host 'amazon.de' do |host|
|
14
|
+
host.build :defualt do |pk|
|
15
|
+
# do something
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end # it
|
20
|
+
|
21
|
+
it 'calls the block if one is given to the build config' do
|
22
|
+
called = false
|
23
|
+
ProductSpy.setup do |config|
|
24
|
+
config.host 'amazon.de' do |host|
|
25
|
+
host.build :default do |pk|
|
26
|
+
called = true
|
27
|
+
pk.should == ['test']
|
28
|
+
"new URL: #{pk.first}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
ProductSpy.build('amazon.de', ['test']).should == "new URL: test"
|
33
|
+
called.should == true
|
34
|
+
end # it
|
35
|
+
end
|
9
36
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: product_spy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
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: 2013-04-
|
12
|
+
date: 2013-04-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: addressable
|