wiki-yggdrasil 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 +4 -4
- data/lib/wiki/article.rb +14 -2
- data/lib/wiki/yggdrasil.rb +11 -6
- data/lib/wiki/yggdrasil/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7cc1cce532c4bfc26091aed492571b4d9ee5e149144d77b5dae53c94e29ad5cc
|
4
|
+
data.tar.gz: 5e2c2a615348df19eb218c49354cc155f9f80a9ea5617ba10dc74f7eccd492e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c62586eaabd45d830f865a9028d0711097306d52ffb309efbd5af283d96e7debd1f2bb2e688ed93d3dbbba0d02383541bb8095f799114ffbd7c30c43364ec99
|
7
|
+
data.tar.gz: cc5b5e8582137e133c7a53e36ed7e32339bd7ea1afea4b80db483e9b8d03c09887f84bb73f643fcd9cead54c51b4a841eb7ba4a701b89738ec1101ca0d26f20d
|
data/lib/wiki/article.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'nokogiri'
|
2
2
|
require 'open-uri'
|
3
|
+
|
3
4
|
module Wiki::Yggdrasil
|
4
5
|
|
5
6
|
class Article
|
@@ -10,8 +11,9 @@ module Wiki::Yggdrasil
|
|
10
11
|
@uri = uri
|
11
12
|
@summary = nil
|
12
13
|
@child_links = nil
|
14
|
+
@name = nil
|
13
15
|
end
|
14
|
-
|
16
|
+
|
15
17
|
def summary
|
16
18
|
@summary ||= Nokogiri::HTML(Nokogiri::HTML(open(self.uri)).to_s.split('<div id="toc" class="toc">')[0]).css('p') ## TODO: Cleanup
|
17
19
|
end
|
@@ -26,6 +28,11 @@ module Wiki::Yggdrasil
|
|
26
28
|
self.summary.css('p a')
|
27
29
|
end
|
28
30
|
|
31
|
+
def name
|
32
|
+
@name ||= Nokogiri::HTML(open(self.uri)).css('#firstHeading').inner_html
|
33
|
+
## TODO: Cleanup
|
34
|
+
end
|
35
|
+
|
29
36
|
def format_links(anchors: self.scrape_all_summary_links)
|
30
37
|
uris = anchors.map do |anchor|
|
31
38
|
anchor.nil? || anchor['href'].nil? ? next : 'https://en.wikipedia.org' << anchor['href'] ## nil href attributes are often self refs (but possibly not always). Ignore them.
|
@@ -33,11 +40,16 @@ module Wiki::Yggdrasil
|
|
33
40
|
|
34
41
|
uris.compact
|
35
42
|
end
|
36
|
-
|
43
|
+
|
37
44
|
def self.is_valid_wiki_article?(uri:)
|
38
45
|
## Is this URI a wikipedia article?
|
39
46
|
uri =~ /.*wikipedia\.org\/wiki\/.+/ ? true : false
|
40
47
|
end
|
41
48
|
|
42
49
|
end
|
50
|
+
|
51
|
+
|
43
52
|
end
|
53
|
+
|
54
|
+
puts Wiki::Yggdrasil::Article.new(uri: 'https://en.wikipedia.org/wiki/Yggdrasil').name
|
55
|
+
|
data/lib/wiki/yggdrasil.rb
CHANGED
@@ -14,17 +14,22 @@ module Wiki
|
|
14
14
|
|
15
15
|
def children(depth: 4, article_children: self.root.child_links)
|
16
16
|
get_children = lambda do |depth, article_children|
|
17
|
-
article_children.
|
17
|
+
article_children.map do |uri|
|
18
|
+
article = Wiki::Yggdrasil::Article.new(uri: uri)
|
18
19
|
if (depth == 1)
|
19
|
-
|
20
|
+
{
|
21
|
+
name: article.name,
|
22
|
+
children: [],
|
23
|
+
}
|
20
24
|
else
|
21
|
-
|
22
|
-
|
23
|
-
|
25
|
+
{
|
26
|
+
name: article.name,
|
27
|
+
children: get_children.call(depth - 1, article.child_links),
|
28
|
+
}
|
24
29
|
end
|
25
30
|
end
|
26
31
|
end
|
27
|
-
|
32
|
+
|
28
33
|
@children ||= get_children.call(depth, article_children)
|
29
34
|
end
|
30
35
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wiki-yggdrasil
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alex0112
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|