Class: FoundationNavigation::Node
- Inherits:
-
Object
- Object
- FoundationNavigation::Node
- Defined in:
- lib/foundation-navigation/node.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #attrs ⇒ Object
-
#initialize(parent, name, options = {}) ⇒ Node
constructor
A new instance of Node.
- #to_s ⇒ Object
Constructor Details
#initialize(parent, name, options = {}) ⇒ Node
Returns a new instance of Node.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/foundation-navigation/node.rb', line 6 def initialize(parent, name, = {}) = @name = name @parent = parent @children = [] if .is_a?(String) = nil @children = [] end end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
4 5 6 |
# File 'lib/foundation-navigation/node.rb', line 4 def children @children end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/foundation-navigation/node.rb', line 4 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/foundation-navigation/node.rb', line 4 def end |
#parent ⇒ Object
Returns the value of attribute parent.
4 5 6 |
# File 'lib/foundation-navigation/node.rb', line 4 def parent @parent end |
Instance Method Details
#attrs ⇒ Object
26 27 28 29 |
# File 'lib/foundation-navigation/node.rb', line 26 def attrs return "" if .nil? .map {|k, v| "#{k}=#{v.inspect}" }.join(" ") end |
#to_s ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/foundation-navigation/node.rb', line 18 def to_s if children.size > 0 "<#{name}#{' ' + attrs unless attrs.empty?}>#{children.join}</#{name}>" else "<#{name}#{' ' + attrs unless attrs.empty?} />" end end |