Class: Wiki::Yggdrasil::Yggdrasil

Inherits:
Object
  • Object
show all
Defined in:
lib/wiki/yggdrasil.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri:) ⇒ Yggdrasil

Returns a new instance of Yggdrasil.



10
11
12
13
# File 'lib/wiki/yggdrasil.rb', line 10

def initialize(uri:)
  @root     = Wiki::Yggdrasil::Article.new(uri: uri)
  @children = nil
end

Instance Attribute Details

#rootObject (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
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/wiki/yggdrasil.rb', line 15

def children(depth: 4, article_children: self.root.child_links)
  get_children = lambda do |depth, article_children|
    article_children.map do |uri|
      article = Wiki::Yggdrasil::Article.new(uri: uri)
      if (depth == 1)
        {
          name: article.name,
          children: [],
        }
      else
        {
          name: article.name,
          children: get_children.call(depth - 1, article.child_links),
        }
      end
    end
  end
  
  @children ||= get_children.call(depth, article_children)
end