class Wiki::Yggdrasil::Yggdrasil
Attributes
root[R]
Public Class Methods
new(uri:)
click to toggle source
# File lib/wiki/yggdrasil.rb, line 10 def initialize(uri:) @root = Wiki::Yggdrasil::Article.new(uri: uri) @children = nil end
Public Instance Methods
children(depth: 4, article_children: self.root.child_links)
click to toggle source
# 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)
click to toggle source
# 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