page_by_page 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/page_by_page.rb +15 -4
- data/lib/page_by_page/{url.rb → enum.rb} +3 -5
- data/lib/page_by_page/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c96552a7455f5395239cef9f555ecba50b2fe8f6
|
4
|
+
data.tar.gz: e3415ab5619370a7a344cb39834d884d605eaedb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ef3e5d85b79c37c2e9c3a5b2319f9cb5036ba6632799f4241ba426fd21cf032015b2ae2d283abdd0805175a99a99834e12686824ce202c3ddf4d4ffd79533b2
|
7
|
+
data.tar.gz: 77ed820bd3e4ece113c752993b1076a992c7e18e80d003d4bd175ae1f70e3387e8ec70fa77af6dd9366b5e03c0c1bb963d0b1038c32443b8526b255006bf0df0
|
data/lib/page_by_page.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'page_by_page/version'
|
2
|
-
require 'page_by_page/
|
2
|
+
require 'page_by_page/enum'
|
3
3
|
require 'nokogiri'
|
4
4
|
require 'open-uri'
|
5
5
|
|
@@ -17,7 +17,7 @@ class PageByPage
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def url tmpl
|
20
|
-
@tmpl = tmpl
|
20
|
+
@tmpl = ERB.new tmpl
|
21
21
|
end
|
22
22
|
|
23
23
|
def selector sl
|
@@ -32,12 +32,19 @@ class PageByPage
|
|
32
32
|
@step = n
|
33
33
|
end
|
34
34
|
|
35
|
+
def to n
|
36
|
+
@to = n
|
37
|
+
end
|
38
|
+
|
35
39
|
def fetch
|
36
|
-
|
40
|
+
enum = Enum.new options
|
37
41
|
items, all_items = [nil], []
|
38
42
|
catch :no_more do
|
39
43
|
until items.empty?
|
40
|
-
|
44
|
+
n = enum.next
|
45
|
+
break if n > limit
|
46
|
+
url = @tmpl.result binding
|
47
|
+
doc = parse url
|
41
48
|
items = doc.css @selector
|
42
49
|
all_items << items
|
43
50
|
end
|
@@ -64,4 +71,8 @@ class PageByPage
|
|
64
71
|
opt
|
65
72
|
end
|
66
73
|
|
74
|
+
def limit
|
75
|
+
@to || Float::INFINITY
|
76
|
+
end
|
77
|
+
|
67
78
|
end
|
@@ -2,18 +2,16 @@ require 'forwardable'
|
|
2
2
|
require 'erb'
|
3
3
|
|
4
4
|
class PageByPage
|
5
|
-
class
|
5
|
+
class Enum
|
6
6
|
extend Forwardable
|
7
7
|
|
8
8
|
def_delegator :@enum, :next
|
9
9
|
|
10
|
-
def initialize
|
11
|
-
@tmpl = ERB.new tmpl
|
10
|
+
def initialize from: 1, step: 1
|
12
11
|
@enum = Enumerator.new do |yielder|
|
13
12
|
n = from
|
14
13
|
loop do
|
15
|
-
|
16
|
-
yielder.yield rendered
|
14
|
+
yielder.yield n
|
17
15
|
n = n + step
|
18
16
|
end
|
19
17
|
end
|
data/lib/page_by_page/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: page_by_page
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ken
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -83,7 +83,7 @@ files:
|
|
83
83
|
- bin/console
|
84
84
|
- bin/setup
|
85
85
|
- lib/page_by_page.rb
|
86
|
-
- lib/page_by_page/
|
86
|
+
- lib/page_by_page/enum.rb
|
87
87
|
- lib/page_by_page/version.rb
|
88
88
|
- page_by_page.gemspec
|
89
89
|
homepage: https://github.com/turnon/page_by_page
|