scraped 0.1.0 → 0.2.0

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: 7f71471b758c81074f1ed52e7d06ee9e2ee7df49
4
- data.tar.gz: a61a2f95fcf2a889aa077fae49f38b387e08accf
3
+ metadata.gz: bf5c0cab0f1d7991d8e20be4a18742d523dee613
4
+ data.tar.gz: 43a801257aace7d860415183fb8b936db92cea2b
5
5
  SHA512:
6
- metadata.gz: c7d4c5948c39db02b97723fd0dec0b916e395526f1eadb62f455d0ab8875281c5c0111ec791fc3924c5605a37dfbc2cd5f635ba91e3200c62213bf648a0170d9
7
- data.tar.gz: 78f1da053d76b752da56cc3da2d4f341e65ca5cf047bebe40f802fe2e1744d0fb86eaccca1177f5bdd756b6b77b934a4368874272f644c1c6bfad9450944a2d1
6
+ metadata.gz: c07ff312f45e7a43ebd88d0894efa224324f0d433212d360c89a268ae121746d236587c16193e1f6bc6474550f8a8110017931fb3958b9ed434e3c4550cfea54
7
+ data.tar.gz: 281394ecbcb4ce1d9563963b311256b498770c3b18a26039b1c0622e9acace957ff81de9806379021f2a9f668ba80fb6a428b72afc3ccad8ae64d7080192c079
data/CHANGELOG.md CHANGED
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](http://keepachangelog.com/)
6
6
  and this project adheres to [Semantic Versioning](http://semver.org/).
7
7
 
8
+ ## 0.2.0 - 2017-01-04
9
+
10
+ ### Changed
11
+
12
+ - The logic that was in the `Scraped` class is now in `Scraped::Document`.
13
+ - `Scraped::HTML` now inherits from `Scraped::Document` rather than `Scraped`.
14
+ - The top level `Scraped` constant is now a `module` instead of a `class`.
15
+
8
16
  ## 0.1.0 - 2017-01-04
9
17
 
10
18
  ### Added
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+ require 'nokogiri'
3
+ require 'field_serializer'
4
+
5
+ module Scraped
6
+ # Abstract class which scrapers can extend to implement their functionality.
7
+ class Document
8
+ include FieldSerializer
9
+
10
+ def self.decorator(klass, config = {})
11
+ decorators << config.merge(decorator: klass)
12
+ end
13
+
14
+ def self.decorators
15
+ @decorators ||= []
16
+ end
17
+
18
+ def self.inherited(klass)
19
+ klass.decorators.concat(decorators)
20
+ super
21
+ end
22
+
23
+ def initialize(response:)
24
+ @original_response = response
25
+ end
26
+
27
+ private
28
+
29
+ attr_reader :original_response
30
+
31
+ def response
32
+ @response ||= ResponseDecorator.new(
33
+ response: original_response,
34
+ decorators: self.class.decorators
35
+ ).response
36
+ end
37
+
38
+ def url
39
+ response.url
40
+ end
41
+ end
42
+ end
data/lib/scraped/html.rb CHANGED
@@ -1,5 +1,5 @@
1
- class Scraped
2
- class HTML < Scraped
1
+ module Scraped
2
+ class HTML < Scraped::Document
3
3
  private
4
4
 
5
5
  def initialize(noko: nil, **args)
@@ -1,7 +1,7 @@
1
1
  require 'scraped/request/strategy'
2
2
  require 'open-uri'
3
3
 
4
- class Scraped
4
+ module Scraped
5
5
  class Request
6
6
  class Strategy
7
7
  class LiveRequest < Strategy
@@ -1,4 +1,4 @@
1
- class Scraped
1
+ module Scraped
2
2
  class Request
3
3
  class Strategy
4
4
  class NotImplementedError < StandardError; end
@@ -1,7 +1,7 @@
1
1
  require 'scraped/request/strategy/live_request'
2
2
  require 'scraped/response'
3
3
 
4
- class Scraped
4
+ module Scraped
5
5
  class Request
6
6
  def initialize(url:, strategies: [Strategy::LiveRequest])
7
7
  @url = url
@@ -1,7 +1,7 @@
1
1
  require 'nokogiri'
2
2
  require 'uri'
3
3
 
4
- class Scraped
4
+ module Scraped
5
5
  class Response
6
6
  class Decorator
7
7
  class AbsoluteUrls < Decorator
@@ -1,4 +1,4 @@
1
- class Scraped
1
+ module Scraped
2
2
  class Response
3
3
  class Decorator
4
4
  def initialize(response:, config: {})
@@ -1,4 +1,4 @@
1
- class Scraped
1
+ module Scraped
2
2
  class Response
3
3
  attr_reader :status, :headers, :body, :url
4
4
 
@@ -1,4 +1,4 @@
1
- class Scraped
1
+ module Scraped
2
2
  class ResponseDecorator
3
3
  def initialize(response:, decorators:)
4
4
  @original_response = response
@@ -1,3 +1,3 @@
1
- class Scraped
2
- VERSION = '0.1.0'.freeze
1
+ module Scraped
2
+ VERSION = '0.2.0'.freeze
3
3
  end
data/lib/scraped.rb CHANGED
@@ -1,42 +1,6 @@
1
1
  # frozen_string_literal: true
2
- require 'nokogiri'
3
- require 'field_serializer'
4
2
  require 'require_all'
5
3
  require_rel 'scraped'
6
4
 
7
- # Abstract class which scrapers can extend to implement their functionality.
8
- class Scraped
9
- include FieldSerializer
10
-
11
- def self.decorator(klass, config = {})
12
- decorators << config.merge(decorator: klass)
13
- end
14
-
15
- def self.decorators
16
- @decorators ||= []
17
- end
18
-
19
- def self.inherited(klass)
20
- klass.decorators.concat(decorators)
21
- super
22
- end
23
-
24
- def initialize(response:)
25
- @original_response = response
26
- end
27
-
28
- private
29
-
30
- attr_reader :original_response
31
-
32
- def response
33
- @response ||= ResponseDecorator.new(
34
- response: original_response,
35
- decorators: self.class.decorators
36
- ).response
37
- end
38
-
39
- def url
40
- response.url
41
- end
5
+ module Scraped
42
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scraped
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - EveryPolitician
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-04 00:00:00.000000000 Z
11
+ date: 2017-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -141,6 +141,7 @@ files:
141
141
  - bin/setup
142
142
  - lib/scraped.rb
143
143
  - lib/scraped/core_ext.rb
144
+ - lib/scraped/document.rb
144
145
  - lib/scraped/html.rb
145
146
  - lib/scraped/request.rb
146
147
  - lib/scraped/request/strategy.rb