scrapework 0.1.1 → 0.1.2

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
  SHA256:
3
- metadata.gz: c58c41ad16325995c414d072e220c583b83f1bdc52778ccc843c706efe745924
4
- data.tar.gz: 0f22e214c0006c0e76a6368b7368b199daf5ce6a53afc3d5b0b76205f198b9da
3
+ metadata.gz: 4d05be6e525594f8a297ad5bae0abaeeb366a198bd4acb450f837449c7c19e93
4
+ data.tar.gz: 0e74bd49022f11e5712e363ef9ddaf9710c37456324cee058596eb00340b2308
5
5
  SHA512:
6
- metadata.gz: fd6af54c141cae5e3eb55c9da405777fca1958f0503f774aa1695444951efc47a9744fa6d3675448acf6c1d1894f552bdcc6e29c9bdaaa1e4bf8bdbcbd879164
7
- data.tar.gz: 011c840fe58b474dc0008eb43e9e9c8a02689dbf1cd3a6e1b8cad56b7a1485183b41ec4b076360803ee56b842a495590fce042bc46d7c792583fc6bb10c6b949
6
+ metadata.gz: 486ebab03674cae60200091d0983c766e61e177a15eb897de4951adf7de46cd2b22614e4d8ea981a5574b70f9388a58212a1e7c35e2a87e7f9f6a3973c552652
7
+ data.tar.gz: db1b96744ebbe5d9833ac20591aa7ba6dc6ad6634ff957c473e6482037f0efe3862d48f2db16c8e42e34822959be4dbd29e36867906895255a2d2cacf11c0ea4
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.1.2
2
+
3
+ * Error in mapped attribute raises `Scrapework::MappingError`
4
+
1
5
  # 0.1.1
2
6
 
3
7
  * Pagination mapped method calls block in context of the object instance.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- scrapework (0.1.0)
4
+ scrapework (0.1.2)
5
5
  active_attr
6
6
  activesupport
7
7
  nokogiri
@@ -27,7 +27,7 @@ GEM
27
27
  jaro_winkler (1.5.2)
28
28
  mini_portile2 (2.4.0)
29
29
  minitest (5.11.3)
30
- nokogiri (1.10.2)
30
+ nokogiri (1.10.3)
31
31
  mini_portile2 (~> 2.4.0)
32
32
  parallel (1.17.0)
33
33
  parser (2.6.2.1)
data/examples/manga.rb CHANGED
@@ -5,6 +5,37 @@ require 'scrapework'
5
5
  # This example sets up several data types and uses them
6
6
  # to download every chapter of a manga.
7
7
 
8
+ # A manga list web page
9
+ class MangaList < Scrapework::Object
10
+ has_many :manga, class: 'Manga'
11
+
12
+ # Will not return the array of full collection
13
+ def each(*args, &block)
14
+ manga.each(*args, &block)
15
+
16
+ next_page&.each(*args, &block)
17
+ end
18
+
19
+ map 'manga' do |html|
20
+ html.css('.update_item h3 a').map do |a|
21
+ { uri: a['href'], title: a.text.strip }
22
+ end
23
+ end
24
+
25
+ paginate do |html|
26
+ pages = html.css('.group-page a').to_a[1..-2]
27
+ current = pages.find_index { |p| p['class'] == 'pageselect' }
28
+
29
+ prev_page_link = pages[current - 1] if current
30
+ next_page_link = pages[current + 1] if current
31
+
32
+ prev_page = { url: prev_page_link['href'] } if prev_page_link
33
+ next_page = { url: next_page_link['href'] } if next_page_link
34
+
35
+ [prev_page, next_page]
36
+ end
37
+ end
38
+
8
39
  # A manga web page
9
40
  class Manga < Scrapework::Object
10
41
  attribute :title
@@ -123,7 +123,11 @@ module Scrapework
123
123
  mapped_method = :"_mapped_#{name}"
124
124
 
125
125
  define_method(mapped_method) do
126
- value = instance_exec(_document, &block)
126
+ value = begin
127
+ instance_exec(_document, &block)
128
+ rescue StandardError => e
129
+ raise MappingError, e.message
130
+ end
127
131
 
128
132
  public_send("#{name}=", value)
129
133
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Scrapework
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
data/lib/scrapework.rb CHANGED
@@ -5,5 +5,7 @@ require 'scrapework/object'
5
5
 
6
6
  module Scrapework
7
7
  class Error < StandardError; end
8
+ class MappingError < Error; end
9
+
8
10
  # Your code goes here...
9
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scrapework
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - jphager2
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-19 00:00:00.000000000 Z
11
+ date: 2019-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_attr