Sha256: 51b57adb9954014b3849b0b5262033941e26267992c87bd4809857b9f9ad6ccd

Contents?: true

Size: 839 Bytes

Versions: 1

Compression:

Stored size: 839 Bytes

Contents

require "wiki/yggdrasil/version"

module Wiki
  module Yggdrasil
    require 'wiki/article'
    
    class Yggdrasil
      attr_reader :root

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

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

        @children ||= get_children.call(depth, article_children)
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wiki-yggdrasil-0.1.0 lib/wiki/yggdrasil.rb