yasuri 0.0.3 → 0.0.4
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.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/app.rb +1 -1
- data/lib/yasuri/version.rb +1 -1
- data/lib/yasuri/yasuri.rb +6 -6
- data/spec/yasuri_spec.rb +9 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 765b5141cd81658858ac62ea8306c399f4edda16
|
4
|
+
data.tar.gz: ecde98805bf7d3536e83496e6ac85ec5767f0321
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b0f3466e7017608ec24b75c15ccc8c2f64fff3b173aa2e818f02c1b115c1796d0e8f901879d5dae7c4de312bec3c309a6f530b3f3f7b65e19b5ee58ccf4db4d
|
7
|
+
data.tar.gz: d6551a758c588a3a0c08865551ebef957863643125607cdb1b6f143f56de62691a76444fc3c85dc455793c61903794b61c0eaeb6515dda6536e130760942d2d0
|
data/README.md
CHANGED
@@ -22,7 +22,7 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
```ruby
|
24
24
|
# Node tree constructing by DSL
|
25
|
-
root = links_root '//*[@id="menu"]/ul/li/a' do
|
25
|
+
root = Yasuri.links_root '//*[@id="menu"]/ul/li/a' do
|
26
26
|
text_title '//*[@id="contents"]/h2'
|
27
27
|
text_content '//*[@id="contents"]/p[1]'
|
28
28
|
end
|
@@ -56,7 +56,7 @@ result = root.inject(agent, root_page)
|
|
56
56
|
|
57
57
|
## Contributing
|
58
58
|
|
59
|
-
1. Fork it ( https://github.com/
|
59
|
+
1. Fork it ( https://github.com/tac0x2a/yasuri/fork )
|
60
60
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
61
61
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
62
62
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/app.rb
CHANGED
@@ -14,7 +14,7 @@ agent = Mechanize.new
|
|
14
14
|
uri = "http://www.asahi.com/"
|
15
15
|
|
16
16
|
# Node tree constructing by DSL
|
17
|
-
root = links_top '//*[@id="MainInner"]/div[1]/ul/li/a' do
|
17
|
+
root = Yasuri.links_top '//*[@id="MainInner"]/div[1]/ul/li/a' do
|
18
18
|
text_title '//*[@id="MainInner"]/div[1]/div/h1'
|
19
19
|
text_article '//*[@id="MainInner"]/div/div[@class="ArticleText"]'
|
20
20
|
end
|
data/lib/yasuri/version.rb
CHANGED
data/lib/yasuri/yasuri.rb
CHANGED
@@ -125,6 +125,12 @@ module Yasuri
|
|
125
125
|
Yasuri.hash2node(json)
|
126
126
|
end
|
127
127
|
|
128
|
+
def self.method_missing(name, *args, &block)
|
129
|
+
generated = Yasuri::NodeGenerator.gen(name, *args, &block)
|
130
|
+
generated || super(name, args)
|
131
|
+
end
|
132
|
+
|
133
|
+
|
128
134
|
private
|
129
135
|
Text2Node = {
|
130
136
|
"text" => TextNode,
|
@@ -157,9 +163,3 @@ module Yasuri
|
|
157
163
|
end
|
158
164
|
end
|
159
165
|
end
|
160
|
-
|
161
|
-
# alias for DSL
|
162
|
-
def method_missing(name, *args, &block)
|
163
|
-
generated = Yasuri::NodeGenerator.gen(name, *args, &block)
|
164
|
-
generated || super(name, args)
|
165
|
-
end
|
data/spec/yasuri_spec.rb
CHANGED
@@ -48,25 +48,25 @@ describe 'Yasuri' do
|
|
48
48
|
end
|
49
49
|
|
50
50
|
it "can be defined by DSL, return single TextNode title" do
|
51
|
-
generated = text_title '/html/body/p[1]'
|
51
|
+
generated = Yasuri.text_title '/html/body/p[1]'
|
52
52
|
original = Yasuri::TextNode.new('/html/body/p[1]', "title")
|
53
53
|
compare_generated_vs_original(generated, original)
|
54
54
|
end
|
55
55
|
|
56
56
|
it "can be truncated with regexp" do
|
57
|
-
node = text_title '/html/body/p[1]', /^[^,]+/
|
57
|
+
node = Yasuri.text_title '/html/body/p[1]', /^[^,]+/
|
58
58
|
actual = node.inject(@agent, @index_page)
|
59
59
|
expect(actual).to eq "Hello"
|
60
60
|
end
|
61
61
|
|
62
62
|
it "can be truncated with regexp" do
|
63
|
-
node = text_title '/html/body/p[1]', /[^,]+$/
|
63
|
+
node = Yasuri.text_title '/html/body/p[1]', /[^,]+$/
|
64
64
|
actual = node.inject(@agent, @index_page)
|
65
65
|
expect(actual).to eq "Yasuri"
|
66
66
|
end
|
67
67
|
|
68
68
|
it "return empty string if truncated with no match to regexp" do
|
69
|
-
node = text_title '/html/body/p[1]', /^hoge/
|
69
|
+
node = Yasuri.text_title '/html/body/p[1]', /^hoge/
|
70
70
|
actual = node.inject(@agent, @index_page)
|
71
71
|
expect(actual).to be_empty
|
72
72
|
end
|
@@ -159,7 +159,7 @@ describe 'Yasuri' do
|
|
159
159
|
end
|
160
160
|
|
161
161
|
it 'can be defined by DSL, scrape all tables' do
|
162
|
-
generated = struct_tables '/html/body/table' do
|
162
|
+
generated = Yasuri.struct_tables '/html/body/table' do
|
163
163
|
struct_table './tr' do
|
164
164
|
text_title './td[1]'
|
165
165
|
text_pub_date './td[2]'
|
@@ -223,12 +223,12 @@ describe 'Yasuri' do
|
|
223
223
|
expect(actual).to match expected
|
224
224
|
end
|
225
225
|
it 'can be defined by DSL, return single LinkNode title' do
|
226
|
-
generated = links_title
|
226
|
+
generated = Yasuri.links_title '/html/body/a'
|
227
227
|
original = Yasuri::LinksNode.new('/html/body/a', "title")
|
228
228
|
compare_generated_vs_original(generated, original)
|
229
229
|
end
|
230
230
|
it 'can be defined by DSL, return nested contents under link' do
|
231
|
-
generated = links_title '/html/body/a' do
|
231
|
+
generated = Yasuri.links_title '/html/body/a' do
|
232
232
|
text_name '/html/body/p'
|
233
233
|
end
|
234
234
|
original = Yasuri::LinksNode.new('/html/body/a', "root", [
|
@@ -238,7 +238,7 @@ describe 'Yasuri' do
|
|
238
238
|
end
|
239
239
|
|
240
240
|
it 'can be defined by DSL, return recursive links node' do
|
241
|
-
generated = links_root '/html/body/a' do
|
241
|
+
generated = Yasuri.links_root '/html/body/a' do
|
242
242
|
text_content '/html/body/p'
|
243
243
|
links_sub_link '/html/body/ul/li/a' do
|
244
244
|
text_sub_page_title '/html/head/title'
|
@@ -298,7 +298,7 @@ describe 'Yasuri' do
|
|
298
298
|
end
|
299
299
|
|
300
300
|
it 'can be defined by DSL, return single PaginateNode content' do
|
301
|
-
generated = pages_next "/html/body/nav/span/a[@class='next']" do
|
301
|
+
generated = Yasuri.pages_next "/html/body/nav/span/a[@class='next']" do
|
302
302
|
text_content '/html/body/p'
|
303
303
|
end
|
304
304
|
original = Yasuri::PaginateNode.new("/html/body/nav/span/a[@class='next']", "root", [
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yasuri
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TAC
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|