ero_getter 1.1.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/ero_getter.gemspec +2 -1
- data/lib/downloader/nijigazou_sokuhou.rb +1 -1
- data/lib/downloader/pm_style.rb +2 -1
- data/lib/ero_getter/base.rb +4 -3
- data/spec/downloader/nijigazou_sokuhou_spec.rb +8 -0
- data/spec/downloader/pm_style_spec.rb +1 -1
- data/spec/ero_getter/base_spec.rb +123 -81
- data/spec/samples/nijigazou_sokuhou/global_last.html +1177 -0
- metadata +3 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0
|
data/ero_getter.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "ero_getter"
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["masarakki"]
|
@@ -38,6 +38,7 @@ Gem::Specification.new do |s|
|
|
38
38
|
"spec/ero_getter/base_spec.rb",
|
39
39
|
"spec/ero_getter_spec.rb",
|
40
40
|
"spec/samples/nijigazou_sokuhou/first.html",
|
41
|
+
"spec/samples/nijigazou_sokuhou/global_last.html",
|
41
42
|
"spec/samples/nijigazou_sokuhou/last.html",
|
42
43
|
"spec/samples/nijigazou_sokuhou/middle.html",
|
43
44
|
"spec/samples/pm_style/test.html",
|
data/lib/downloader/pm_style.rb
CHANGED
@@ -5,6 +5,7 @@ class PmStyle < EroGetter::Base
|
|
5
5
|
path.parent[:href] if path[:alt] =~ /file\d+/
|
6
6
|
end
|
7
7
|
sub_directory do
|
8
|
-
targets.first.match(/pm_(
|
8
|
+
matches = targets.first.match(/pm_(.+?)(\d+)[a|b|c].zip$/)
|
9
|
+
"pm_#{matches[1]}_#{"%06d" % matches[2]}"
|
9
10
|
end
|
10
11
|
end
|
data/lib/ero_getter/base.rb
CHANGED
@@ -122,13 +122,14 @@ class EroGetter::Base
|
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
125
|
-
def
|
125
|
+
def connection(css, &block)
|
126
126
|
[:prev, :next].each_with_index do |method_name, index|
|
127
127
|
var_name = "@#{method_name}".to_sym
|
128
128
|
define_method(method_name) do
|
129
129
|
unless instance_variable_defined?(var_name)
|
130
|
-
tag = document.
|
131
|
-
instance_variable_set(var_name,
|
130
|
+
tag = document.css(css[index]).first
|
131
|
+
instance_variable_set(var_name,
|
132
|
+
tag && instance_exec(tag, &block) ? tag[:href] : nil)
|
132
133
|
end
|
133
134
|
instance_variable_get(var_name)
|
134
135
|
end
|
@@ -43,5 +43,13 @@ describe NijigazouSokuhou do
|
|
43
43
|
its(:next) { should be_nil }
|
44
44
|
its(:prev) { should == url }
|
45
45
|
end
|
46
|
+
|
47
|
+
context :global_last do
|
48
|
+
before do
|
49
|
+
fake(:get, url, 'nijigazou_sokuhou/global_last.html')
|
50
|
+
end
|
51
|
+
|
52
|
+
its(:next) { should be_nil }
|
53
|
+
end
|
46
54
|
end
|
47
55
|
end
|
@@ -14,6 +14,6 @@ describe PmStyle do
|
|
14
14
|
'http://hpcgi2.nifty.com/r-seven/page.cgi?file=copy2/pm/120526/pm_chu2800b.zip',
|
15
15
|
'http://hpcgi2.nifty.com/r-seven/page.cgi?file=copy2/pm/120526/pm_chu2800c.zip']
|
16
16
|
}
|
17
|
-
its(:sub_directory) { should == '
|
17
|
+
its(:sub_directory) { should == 'pm_chu_002800' }
|
18
18
|
end
|
19
19
|
|
@@ -2,112 +2,154 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe EroGetter::Base do
|
4
4
|
let(:regex) { %r{http://example.net/\d+.html} }
|
5
|
-
|
6
|
-
|
7
|
-
fake(:get, regex, 'sample.html')
|
8
|
-
@klazz = Class.new(EroGetter::Base) do
|
9
|
-
name 'NijiEro BBS'
|
10
|
-
url _regex
|
5
|
+
let(:url) { 'http://example.net/10101010.html' }
|
6
|
+
subject { @dl }
|
11
7
|
|
12
|
-
|
13
|
-
|
14
|
-
|
8
|
+
context :without_connection do
|
9
|
+
before do
|
10
|
+
_regex = regex
|
11
|
+
fake(:get, regex, 'sample.html')
|
12
|
+
@klazz = Class.new(EroGetter::Base) do
|
13
|
+
name 'NijiEro BBS'
|
14
|
+
url _regex
|
15
|
+
|
16
|
+
target "ul#sources li a" do |elm|
|
17
|
+
elm[:href]
|
18
|
+
end
|
15
19
|
|
16
|
-
|
17
|
-
|
20
|
+
sub_directory do
|
21
|
+
targets.map{|x| x.split(%r{/}).last }.join('/')
|
22
|
+
end
|
18
23
|
end
|
24
|
+
@klazz.stub(:to_s).and_return('TestClass')
|
19
25
|
end
|
20
|
-
@klazz.stub(:to_s).and_return('TestClass')
|
21
|
-
end
|
22
26
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
+
describe "assign url_mapping" do
|
28
|
+
it { EroGetter.url_mapping.should have_key regex }
|
29
|
+
it { EroGetter.url_mapping[regex].should == @klazz }
|
30
|
+
end
|
27
31
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
EroGetter.stub('directory').and_return('/tmp')
|
35
|
-
end
|
36
|
-
its(:name) { should == 'NijiEro BBS' }
|
37
|
-
its(:url_regex) { should == regex }
|
38
|
-
its(:base_dir) { should == 'test_class' }
|
39
|
-
its(:http_client) { should be_a HTTPClient }
|
40
|
-
its(:document) { should be_a Nokogiri::HTML::Document }
|
41
|
-
its(:title) { should == 'EroGetter Server' }
|
42
|
-
its(:url) { should == 'http://example.net/10101010.html' }
|
43
|
-
its(:direction) { should == :none }
|
44
|
-
its(:targets) { should == ['https://github.com/masarakki/ero_getter_server',
|
45
|
-
'https://github.com/masarakki/ero_getter_chrome_extension'] }
|
46
|
-
its(:sub_directory) { should == 'ero_getter_server/ero_getter_chrome_extension' }
|
47
|
-
its(:directory) { should == '/tmp/test_class/ero_getter_server/ero_getter_chrome_extension' }
|
48
|
-
describe :after_run do
|
49
|
-
context :not_set_after do
|
50
|
-
its(:run_next?) { should be_false }
|
51
|
-
its(:run_prev?) { should be_false }
|
32
|
+
describe :instance_methods do
|
33
|
+
context :good do
|
34
|
+
before do
|
35
|
+
@dl = @klazz.new(url)
|
36
|
+
EroGetter.stub(:mkdir).and_return(true)
|
37
|
+
EroGetter.stub('directory').and_return('/tmp')
|
52
38
|
end
|
39
|
+
its(:name) { should == 'NijiEro BBS' }
|
40
|
+
its(:url_regex) { should == regex }
|
41
|
+
its(:base_dir) { should == 'test_class' }
|
42
|
+
its(:http_client) { should be_a HTTPClient }
|
43
|
+
its(:document) { should be_a Nokogiri::HTML::Document }
|
44
|
+
its(:title) { should == 'EroGetter Server' }
|
45
|
+
its(:url) { should == url }
|
46
|
+
its(:direction) { should == :none }
|
47
|
+
its(:targets) { should == ['https://github.com/masarakki/ero_getter_server',
|
48
|
+
'https://github.com/masarakki/ero_getter_chrome_extension'] }
|
49
|
+
its(:sub_directory) { should == 'ero_getter_server/ero_getter_chrome_extension' }
|
50
|
+
its(:directory) { should == '/tmp/test_class/ero_getter_server/ero_getter_chrome_extension' }
|
53
51
|
|
54
|
-
|
55
|
-
context :
|
56
|
-
|
57
|
-
@dl.stub(:next).and_return('hoge')
|
58
|
-
end
|
59
|
-
its(:run_next?) { should be_true }
|
52
|
+
describe :after_run do
|
53
|
+
context :not_set_after do
|
54
|
+
its(:run_next?) { should be_false }
|
60
55
|
its(:run_prev?) { should be_false }
|
61
56
|
end
|
62
|
-
|
63
|
-
|
64
|
-
|
57
|
+
|
58
|
+
context :direction_none do
|
59
|
+
context :has_next do
|
60
|
+
before do
|
61
|
+
@dl.stub(:next).and_return('hoge')
|
62
|
+
end
|
63
|
+
its(:run_next?) { should be_true }
|
64
|
+
its(:run_prev?) { should be_false }
|
65
65
|
end
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
66
|
+
context :has_prev do
|
67
|
+
before do
|
68
|
+
@dl.stub(:prev).and_return('hoge')
|
69
|
+
end
|
70
|
+
its(:run_next?) { should be_false }
|
71
|
+
its(:run_prev?) { should be_true }
|
72
|
+
end
|
73
|
+
context :has_next_and_prev do
|
74
|
+
before do
|
75
|
+
@dl.stub(:prev).and_return('hoge')
|
76
|
+
@dl.stub(:next).and_return('hoge')
|
77
|
+
end
|
78
|
+
its(:run_next?) { should be_true }
|
79
|
+
its(:run_prev?) { should be_true }
|
73
80
|
end
|
74
|
-
its(:run_next?) { should be_true }
|
75
|
-
its(:run_prev?) { should be_true }
|
76
81
|
end
|
77
|
-
end
|
78
82
|
|
79
|
-
|
80
|
-
before do
|
81
|
-
@dl.stub(:direction).and_return(:prev)
|
82
|
-
end
|
83
|
-
context :has_next do
|
83
|
+
context :direction_prev do
|
84
84
|
before do
|
85
|
-
@dl.stub(:
|
85
|
+
@dl.stub(:direction).and_return(:prev)
|
86
|
+
end
|
87
|
+
context :has_next do
|
88
|
+
before do
|
89
|
+
@dl.stub(:next).and_return('hoge')
|
90
|
+
end
|
91
|
+
its(:run_next?) { should be_false }
|
86
92
|
end
|
87
|
-
its(:run_next?) { should be_false }
|
88
93
|
end
|
89
|
-
end
|
90
94
|
|
91
|
-
|
92
|
-
before do
|
93
|
-
@dl.stub(:direction).and_return(:next)
|
94
|
-
end
|
95
|
-
context :has_pref do
|
95
|
+
context :direction_next do
|
96
96
|
before do
|
97
|
-
@dl.stub(:
|
97
|
+
@dl.stub(:direction).and_return(:next)
|
98
|
+
end
|
99
|
+
context :has_pref do
|
100
|
+
before do
|
101
|
+
@dl.stub(:prev).and_return('hoge')
|
102
|
+
end
|
103
|
+
its(:run_prev?) { should be_false }
|
98
104
|
end
|
99
|
-
its(:run_prev?) { should be_false }
|
100
105
|
end
|
101
106
|
end
|
102
107
|
end
|
108
|
+
|
109
|
+
context :url_mismatch do
|
110
|
+
it {
|
111
|
+
lambda {
|
112
|
+
@klazz.new('http://example.com/10101010.html')
|
113
|
+
}.should raise_error
|
114
|
+
}
|
115
|
+
end
|
103
116
|
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe :connection do
|
120
|
+
before do
|
121
|
+
_regex = regex
|
122
|
+
klazz = Class.new(EroGetter::Base) do
|
123
|
+
url _regex
|
104
124
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
125
|
+
connection ['a[rel=prev]', 'a[rel=next]'] do |path|
|
126
|
+
path
|
127
|
+
end
|
128
|
+
end
|
129
|
+
@dl = klazz.new(url)
|
130
|
+
end
|
131
|
+
|
132
|
+
context :css_not_found do
|
133
|
+
before do
|
134
|
+
@dl.document.stub(:css).and_return([])
|
135
|
+
end
|
136
|
+
its(:prev) { should be_nil }
|
137
|
+
its(:next) { should be_nil }
|
138
|
+
end
|
139
|
+
context :css_find_but_invalid do
|
140
|
+
before do
|
141
|
+
@dl.document.stub(:css).and_return([false, true, true])
|
142
|
+
end
|
143
|
+
its(:prev) { should be_nil }
|
144
|
+
its(:next) { should be_nil }
|
145
|
+
end
|
146
|
+
context :css_find_and_valid do
|
147
|
+
before do
|
148
|
+
x = {:href => 'unko'}
|
149
|
+
@dl.document.stub(:css).and_return([x])
|
150
|
+
end
|
151
|
+
its(:prev) { should == 'unko' }
|
152
|
+
its(:next) { should == 'unko' }
|
111
153
|
end
|
112
154
|
end
|
113
155
|
end
|