yasuri 0.0.10 → 0.0.11
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/lib/yasuri/version.rb +1 -1
- data/lib/yasuri/yasuri_node_generator.rb +4 -7
- data/lib/yasuri/yasuri_text_node.rb +8 -4
- data/spec/yasuri_paginate_node_spec.rb +1 -1
- data/spec/yasuri_spec.rb +0 -3
- data/spec/yasuri_text_node_spec.rb +16 -4
- 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: 2d97799a28c2b4d1991ce32abf50b81bce1cae5f
|
4
|
+
data.tar.gz: d94f15f6056e52f87feb1538964e8a049afb7fcb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 193bb19ac39e9ea1ca74b2c44dc8c66840f630dcdcd32797acf28a6add47b9a5d878a9ffe3a482a544eccc75dc0f34aa03a4d199dffd311b6dc134f6471b5d35
|
7
|
+
data.tar.gz: 3a360133ce54adb4bcc16637a53d78d1cbd5402d64c47b4afc8e852918f4ea613b4eea9ab20e8bf8c325cb67bf57c31577fa45ba9c04b98d186aa1a72b913f64
|
data/lib/yasuri/version.rb
CHANGED
@@ -28,16 +28,13 @@ module Yasuri
|
|
28
28
|
|
29
29
|
case name
|
30
30
|
when /^text_(.+)$/
|
31
|
-
|
32
|
-
Yasuri::TextNode.new(xpath, $1, children || [], truncate: truncate)
|
31
|
+
Yasuri::TextNode.new(xpath, $1, children || [], *opt)
|
33
32
|
when /^struct_(.+)$/
|
34
|
-
Yasuri::StructNode.new(xpath, $1, children || [])
|
33
|
+
Yasuri::StructNode.new(xpath, $1, children || [], *opt)
|
35
34
|
when /^links_(.+)$/
|
36
|
-
Yasuri::LinksNode.new(xpath, $1, children || [])
|
35
|
+
Yasuri::LinksNode.new(xpath, $1, children || [], *opt)
|
37
36
|
when /^pages_(.+)$/
|
38
|
-
|
39
|
-
limit = limit || Float::MAX
|
40
|
-
Yasuri::PaginateNode.new(xpath, $1, children || [], limit: limit)
|
37
|
+
Yasuri::PaginateNode.new(xpath, $1, children || [], *opt)
|
41
38
|
else
|
42
39
|
nil
|
43
40
|
end
|
@@ -7,13 +7,15 @@ module Yasuri
|
|
7
7
|
class TextNode
|
8
8
|
include Node
|
9
9
|
|
10
|
-
def initialize(xpath, name, children = [], truncate: nil)
|
10
|
+
def initialize(xpath, name, children = [], truncate: nil, proc:nil)
|
11
11
|
super(xpath, name, children)
|
12
12
|
|
13
13
|
truncate = Regexp.new(truncate) if not truncate.nil? # regexp or nil
|
14
|
-
|
15
14
|
@truncate = truncate
|
16
15
|
@truncate = Regexp.new(@truncate.to_s) if not @truncate.nil?
|
16
|
+
|
17
|
+
@proc = proc.nil? ? nil : proc.to_sym
|
18
|
+
|
17
19
|
end
|
18
20
|
|
19
21
|
def inject(agent, page, opt = {})
|
@@ -25,10 +27,12 @@ module Yasuri
|
|
25
27
|
text = matches ? matches[1] || matches[0] || text : ""
|
26
28
|
end
|
27
29
|
|
28
|
-
text.
|
30
|
+
text = text.__send__(@proc) if @proc && text.respond_to?(@proc)
|
31
|
+
text
|
29
32
|
end
|
33
|
+
|
30
34
|
def opts
|
31
|
-
{truncate:@truncate}
|
35
|
+
{truncate:@truncate, proc:@proc}
|
32
36
|
end
|
33
37
|
end
|
34
38
|
end
|
@@ -73,7 +73,7 @@ describe 'Yasuri' do
|
|
73
73
|
end
|
74
74
|
|
75
75
|
it 'can be defined by DSL, return single PaginateNode content limited' do
|
76
|
-
generated = Yasuri.pages_next "/html/body/nav/span/a[@class='next']", 2 do
|
76
|
+
generated = Yasuri.pages_next "/html/body/nav/span/a[@class='next']", limit:2 do
|
77
77
|
text_content '/html/body/p'
|
78
78
|
end
|
79
79
|
original = Yasuri::PaginateNode.new("/html/body/nav/span/a[@class='next']", "root", [
|
data/spec/yasuri_spec.rb
CHANGED
@@ -41,27 +41,39 @@ describe 'Yasuri' do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
it "can be truncated with regexp" do
|
44
|
-
node = Yasuri.text_title '/html/body/p[1]',
|
44
|
+
node = Yasuri.text_title '/html/body/p[1]', truncate:/^[^,]+/
|
45
45
|
actual = node.inject(@agent, @index_page)
|
46
46
|
expect(actual).to eq "Hello"
|
47
47
|
end
|
48
48
|
|
49
49
|
it "return first captured if matched given capture pattern" do
|
50
|
-
node = Yasuri.text_title '/html/body/p[1]',
|
50
|
+
node = Yasuri.text_title '/html/body/p[1]', truncate:/H(.+)i/
|
51
51
|
actual = node.inject(@agent, @index_page)
|
52
52
|
expect(actual).to eq "ello,Yasur"
|
53
53
|
end
|
54
54
|
|
55
55
|
it "can be truncated with regexp" do
|
56
|
-
node = Yasuri.text_title '/html/body/p[1]',
|
56
|
+
node = Yasuri.text_title '/html/body/p[1]', truncate:/[^,]+$/
|
57
57
|
actual = node.inject(@agent, @index_page)
|
58
58
|
expect(actual).to eq "Yasuri"
|
59
59
|
end
|
60
60
|
|
61
61
|
it "return empty string if truncated with no match to regexp" do
|
62
|
-
node = Yasuri.text_title '/html/body/p[1]',
|
62
|
+
node = Yasuri.text_title '/html/body/p[1]', truncate:/^hoge/
|
63
63
|
actual = node.inject(@agent, @index_page)
|
64
64
|
expect(actual).to be_empty
|
65
65
|
end
|
66
|
+
|
67
|
+
it "return symbol method applied string" do
|
68
|
+
node = Yasuri.text_title '/html/body/p[1]', proc: :upcase
|
69
|
+
actual = node.inject(@agent, @index_page)
|
70
|
+
expect(actual).to eq "HELLO,YASURI"
|
71
|
+
end
|
72
|
+
|
73
|
+
it "return apply multi arguments" do
|
74
|
+
node = Yasuri.text_title '/html/body/p[1]', proc: :upcase, truncate:/H(.+)i/
|
75
|
+
actual = node.inject(@agent, @index_page)
|
76
|
+
expect(actual).to eq "ELLO,YASUR"
|
77
|
+
end
|
66
78
|
end
|
67
79
|
end
|
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.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TAC
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|