Class: FoundationNavigation::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/foundation-navigation/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  @options = options
  @name = name
  @parent = parent
  @children = []

  if options.is_a?(String)
    @options = nil
    @children = [options]
  end
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



4
5
6
# File 'lib/foundation-navigation/node.rb', line 4

def children
  @children
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/foundation-navigation/node.rb', line 4

def name
  @name
end

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/foundation-navigation/node.rb', line 4

def options
  @options
end

#parentObject

Returns the value of attribute parent.



4
5
6
# File 'lib/foundation-navigation/node.rb', line 4

def parent
  @parent
end

Instance Method Details

#attrsObject



26
27
28
29
# File 'lib/foundation-navigation/node.rb', line 26

def attrs
  return "" if options.nil?
  options.map {|k, v| "#{k}=#{v.inspect}" }.join(" ")
end

#to_sObject



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