earl 1.0.0 → 2.0.0
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 +7 -0
- data/.github/workflows/ruby-tests.yml +32 -0
- data/.gitignore +20 -4
- data/.rubocop.yml +35 -0
- data/.rubocop_todo.yml +22 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +15 -3
- data/Guardfile +9 -4
- data/LICENSE +3 -1
- data/{README.rdoc → README.md} +44 -46
- data/Rakefile +7 -32
- data/earl.gemspec +19 -20
- data/lib/earl/earl.rb +63 -49
- data/lib/earl/scraper.rb +16 -17
- data/lib/earl/version.rb +3 -1
- data/lib/earl.rb +6 -0
- data/spec/fixtures/cassettes/feed/is_atom_feed.yml +2298 -0
- data/spec/fixtures/cassettes/feed/is_rss_feed.yml +48 -0
- data/spec/fixtures/cassettes/feed/no_feed.yml +69 -0
- data/spec/fixtures/cassettes/feed/with_atom_and_rss_feed.yml +1471 -0
- data/spec/fixtures/cassettes/feed/with_rss_feed.yml +47 -0
- data/spec/fixtures/cassettes/oembed/no_oembed.yml +101 -0
- data/spec/fixtures/cassettes/oembed/youtube_oembed.yml +129 -0
- data/spec/integration/feed_spec.rb +54 -54
- data/spec/integration/oembed_spec.rb +23 -27
- data/spec/spec_helper.rb +4 -2
- data/spec/support/fixtures.rb +8 -3
- data/spec/support/vcr.rb +9 -0
- data/spec/unit/earl/earl_spec.rb +5 -6
- data/spec/unit/earl/feed_spec.rb +29 -26
- data/spec/unit/earl/oembed_spec.rb +24 -23
- data/spec/unit/earl/scraper_spec.rb +19 -18
- data/spec/unit/earl_spec.rb +39 -30
- metadata +48 -97
- data/.document +0 -5
- data/.rspec +0 -1
- data/.travis.yml +0 -11
- data/Gemfile.lock +0 -60
- data/script/console +0 -10
data/lib/earl/scraper.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Base class for nokogiri page scraping
|
4
|
+
class Earl::Scraper
|
3
5
|
class << self
|
4
6
|
@@registry = []
|
5
|
-
attr_reader :regexp
|
6
|
-
attr_reader :attributes
|
7
|
+
attr_reader :regexp, :attributes
|
7
8
|
|
8
9
|
def match(regexp)
|
9
10
|
@regexp = regexp
|
@@ -17,17 +18,15 @@ class Earl::Scraper
|
|
17
18
|
|
18
19
|
def for(url, earl_source)
|
19
20
|
@@registry.each do |klass|
|
20
|
-
return klass.new(url,earl_source) if klass.regexp.match(url)
|
21
|
+
return klass.new(url, earl_source) if klass.regexp.match(url)
|
21
22
|
end
|
22
|
-
|
23
|
+
Earl::Scraper.new(url, earl_source)
|
23
24
|
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
30
|
-
|
26
|
+
def register(scraper_klass)
|
27
|
+
@@registry << scraper_klass
|
28
|
+
end
|
29
|
+
private :register
|
31
30
|
end
|
32
31
|
|
33
32
|
attr_reader :earl_source
|
@@ -42,8 +41,9 @@ class Earl::Scraper
|
|
42
41
|
end
|
43
42
|
|
44
43
|
def attribute(name)
|
45
|
-
return unless
|
46
|
-
|
44
|
+
return unless attribute?(name)
|
45
|
+
|
46
|
+
attributes[name].call(response)
|
47
47
|
end
|
48
48
|
|
49
49
|
def attributes
|
@@ -54,9 +54,10 @@ class Earl::Scraper
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
def
|
57
|
+
def attribute?(name)
|
58
58
|
return false unless self.class.attributes
|
59
|
-
|
59
|
+
|
60
|
+
attributes.key?(name)
|
60
61
|
end
|
61
62
|
|
62
63
|
define_attribute :title do |doc|
|
@@ -88,6 +89,4 @@ class Earl::Scraper
|
|
88
89
|
element['href']
|
89
90
|
end
|
90
91
|
end
|
91
|
-
|
92
92
|
end
|
93
|
-
|
data/lib/earl/version.rb
CHANGED