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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f70e0281f160fbabc3bff893ce607fb400d4b352
4
- data.tar.gz: 768589a35a856f392eadf6d3eaa1410cf8d97fb0
3
+ metadata.gz: 2d97799a28c2b4d1991ce32abf50b81bce1cae5f
4
+ data.tar.gz: d94f15f6056e52f87feb1538964e8a049afb7fcb
5
5
  SHA512:
6
- metadata.gz: 795dec45d612eb40f55aee0fce492979cade151d7f553e0f8e9a77e7ab39f55f3db015c20b6f13f447d991861c8b9c3bf9f25111a1af918ca055002f67491a76
7
- data.tar.gz: 74452e32d9c91ceac9cc4d43963d3f0b68692474239770a55c14c52e6d9f266e28d768c1368211140dc8925acc9e41ce97bf91790fb19cc56366505f1db74894
6
+ metadata.gz: 193bb19ac39e9ea1ca74b2c44dc8c66840f630dcdcd32797acf28a6add47b9a5d878a9ffe3a482a544eccc75dc0f34aa03a4d199dffd311b6dc134f6471b5d35
7
+ data.tar.gz: 3a360133ce54adb4bcc16637a53d78d1cbd5402d64c47b4afc8e852918f4ea613b4eea9ab20e8bf8c325cb67bf57c31577fa45ba9c04b98d186aa1a72b913f64
@@ -1,3 +1,3 @@
1
1
  module Yasuri
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
@@ -28,16 +28,13 @@ module Yasuri
28
28
 
29
29
  case name
30
30
  when /^text_(.+)$/
31
- truncate, dummy = *opt
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
- limit, dummy = *opt
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.to_s
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
@@ -3,9 +3,6 @@
3
3
  # Author:: TAC (tac@tac42.net)
4
4
 
5
5
  require_relative 'spec_helper'
6
- require_relative 'yasuri_text_node_spec'
7
-
8
- #require_relative '../lib/yasuri/yasuri'
9
6
 
10
7
  describe 'Yasuri' do
11
8
  include_context 'httpserver'
@@ -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]', /H(.+)i/
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]', /^hoge/
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.10
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-02 00:00:00.000000000 Z
11
+ date: 2015-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler