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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8f4ae9437d8b93ffeae964877df913939a700cfa
4
- data.tar.gz: 79f64e3d36c7b982aa5bbe2c92222520c83f03ff
3
+ metadata.gz: c96552a7455f5395239cef9f555ecba50b2fe8f6
4
+ data.tar.gz: e3415ab5619370a7a344cb39834d884d605eaedb
5
5
  SHA512:
6
- metadata.gz: 65519fdc3814f678b812fa85b7d298352a68a95f998e8eb8a0fd5c1ba775ee192e15d08957639147fa5803691764e9015a7d9d99c55d4f49256bb720988dfb4f
7
- data.tar.gz: d5025ffd44d32a089c7f709ffebf8af59f4c29cc77a60f2f257d02f5bf2123da6a78b2e807aedd5dd95aa22f7428dd2d4aa8a8789b2b10cb6c2facaeb6afa728
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/url'
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
- url = Url.new @tmpl, options
40
+ enum = Enum.new options
37
41
  items, all_items = [nil], []
38
42
  catch :no_more do
39
43
  until items.empty?
40
- doc = parse url.next
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 Url
5
+ class Enum
6
6
  extend Forwardable
7
7
 
8
8
  def_delegator :@enum, :next
9
9
 
10
- def initialize tmpl, from: 1, step: 1
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
- rendered = @tmpl.result binding
16
- yielder.yield rendered
14
+ yielder.yield n
17
15
  n = n + step
18
16
  end
19
17
  end
@@ -1,3 +1,3 @@
1
1
  class PageByPage
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
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.3
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: 2016-12-31 00:00:00.000000000 Z
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/url.rb
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