Class: Kayessess::Node
- Inherits:
-
Object
- Object
- Kayessess::Node
- Defined in:
- lib/kayessess/node.rb
Overview
Node represents an item in a Tree. It provides some helpers for navigating the tree that is constructed from styleguide reference paths.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#children_hash ⇒ Object
Returns the value of attribute children_hash.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#sections_hash ⇒ Object
Returns the value of attribute sections_hash.
Instance Method Summary collapse
- #children ⇒ Object
-
#initialize(id, name, parent = nil, children_hash = {}, sections_hash = {}) ⇒ Node
constructor
A new instance of Node.
- #is_section? ⇒ Boolean
- #parents(&block) ⇒ Object
- #sections ⇒ Object
- #to_param ⇒ Object
- #to_path ⇒ Object
Constructor Details
#initialize(id, name, parent = nil, children_hash = {}, sections_hash = {}) ⇒ Node
Returns a new instance of Node.
11 12 13 14 15 16 17 |
# File 'lib/kayessess/node.rb', line 11 def initialize(id, name, parent = nil, children_hash = {}, sections_hash = {}) @id = id @name = name @parent = parent @children_hash = children_hash @sections_hash = sections_hash end |
Instance Attribute Details
#children_hash ⇒ Object
Returns the value of attribute children_hash.
9 10 11 |
# File 'lib/kayessess/node.rb', line 9 def children_hash @children_hash end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
8 9 10 |
# File 'lib/kayessess/node.rb', line 8 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/kayessess/node.rb', line 8 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
8 9 10 |
# File 'lib/kayessess/node.rb', line 8 def parent @parent end |
#sections_hash ⇒ Object
Returns the value of attribute sections_hash.
9 10 11 |
# File 'lib/kayessess/node.rb', line 9 def sections_hash @sections_hash end |
Instance Method Details
#children ⇒ Object
39 40 41 |
# File 'lib/kayessess/node.rb', line 39 def children @children_hash.values end |
#is_section? ⇒ Boolean
47 48 49 |
# File 'lib/kayessess/node.rb', line 47 def is_section? false end |
#parents(&block) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/kayessess/node.rb', line 30 def parents(&block) return to_enum(:parents) unless block_given? node = self while node = node.parent do break if node.nil? yield node end end |
#sections ⇒ Object
43 44 45 |
# File 'lib/kayessess/node.rb', line 43 def sections @sections_hash.values end |
#to_param ⇒ Object
19 20 21 |
# File 'lib/kayessess/node.rb', line 19 def to_param name.to_slug end |
#to_path ⇒ Object
23 24 25 26 27 28 |
# File 'lib/kayessess/node.rb', line 23 def to_path File.join(parents.reduce([self.to_param]) {|paths, node| paths << node.to_param unless node.parent.nil? paths }.reverse) end |