Class: Wiki::Yggdrasil::Yggdrasil
- Inherits:
-
Object
- Object
- Wiki::Yggdrasil::Yggdrasil
- Defined in:
- lib/wiki/yggdrasil.rb
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #children(depth: 4, article_children: self.root.child_links) ⇒ Object
-
#initialize(uri:) ⇒ Yggdrasil
constructor
A new instance of Yggdrasil.
- #recursive_scrape(depth: 1, children: @root.child_links) ⇒ Object
Constructor Details
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
8 9 10 |
# File 'lib/wiki/yggdrasil.rb', line 8 def root @root end |
Instance Method Details
#children(depth: 4, article_children: self.root.child_links) ⇒ Object
15 16 17 |
# File 'lib/wiki/yggdrasil.rb', line 15 def children(depth: 4, article_children: self.root.child_links) @children ||= { name: self.root.name, children: recursive_scrape(depth: depth), index: 0, depth: 0 } end |
#recursive_scrape(depth: 1, children: @root.child_links) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/wiki/yggdrasil.rb', line 19 def recursive_scrape(depth: 1, children: @root.child_links) children.each_with_index.map do |uri, index| article = Wiki::Yggdrasil::Article.new(uri: uri) if (depth == 1) { name: article.name, index: index + 1, level: depth, children: [], } else { name: article.name, index: index + 1, level: depth, children: recursive_scrape(depth - 1, article.child_links), } end end end |