Class: Kayessess::Tree

Inherits:
Object
  • Object
show all
Defined in:
lib/kayessess/tree.rb

Overview

Tree is responsible for building a graph that represents the styleguide section heirarchy.

Instance Method Summary collapse

Constructor Details

#initialize(sections) ⇒ Tree

Returns a new instance of Tree.



10
11
12
# File 'lib/kayessess/tree.rb', line 10

def initialize(sections)
  @tree = build_tree(sections)
end

Instance Method Details

#node_for_path(path) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/kayessess/tree.rb', line 22

def node_for_path(path)
  path.map(&:to_slug).reduce(@tree) {|branch, path|
    if branch
      branch = branch.children_hash[path] || branch.sections_hash[path]
    else
      raise Kayessess::SectionNotFound
    end
  }
end

#rootObject



14
15
16
# File 'lib/kayessess/tree.rb', line 14

def root
  @tree
end

#root_sectionsObject



18
19
20
# File 'lib/kayessess/tree.rb', line 18

def root_sections
  root.children
end