Sha256: 057260756c23ab954c0d692e1c807d111c27a9186d4d01cdcf17aaae768906f4

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

module Gollum
  module DescendantTree
    class TreeBuilder

      def initialize (wiki, name)
        @wiki = wiki
        @name = name
        @current_nest_index = 0
      end

      def tree
        current_page_name = get_current_page_name
        page_descendants = []
        @wiki.pages.each do |page|
          set_current_nest_index(page) if page.filename == @name
          if (page.url_path.include?(current_page_name))
            page_descendants << {
              title: page.title,
              url_path: page.url_path,
              nest_index: get_current_index(page)
            }
          end
          
        end
        page_descendants
      end

      private
      
      def set_current_nest_index(page)
        @current_nest_index = get_path_array(page).length
      end

      def get_current_index(page)
        get_path_array(page).length - @current_nest_index
      end

      def get_current_page_name
        @name.split('.').first
      end

      def get_path_array(page)
        return page.url_path.split('/')
      end

    end  
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gollum-descendant_tree-0.0.2 lib/gollum/descendant_tree/tree_builder.rb