Class: Apache::Node
- Inherits:
-
Object
- Object
- Apache::Node
- Defined in:
- lib/apache_config/node.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#content ⇒ Object
Returns the value of attribute content.
-
#name ⇒ Object
Returns the value of attribute name.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #<<(node) ⇒ Object
- #[](name) ⇒ Object
- #hasChildren? ⇒ Boolean
-
#initialize(name, content = nil) ⇒ Node
constructor
A new instance of Node.
- #isRoot? ⇒ Boolean
Constructor Details
#initialize(name, content = nil) ⇒ Node
Returns a new instance of Node.
5 6 7 |
# File 'lib/apache_config/node.rb', line 5 def initialize name, content = nil @name, @content = name, content end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
3 4 5 |
# File 'lib/apache_config/node.rb', line 3 def children @children end |
#content ⇒ Object
Returns the value of attribute content.
3 4 5 |
# File 'lib/apache_config/node.rb', line 3 def content @content end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/apache_config/node.rb', line 3 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent.
3 4 5 |
# File 'lib/apache_config/node.rb', line 3 def parent @parent end |
Instance Method Details
#<<(node) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/apache_config/node.rb', line 21 def << node @children ||= [] @children << node node.parent = self node end |
#[](name) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/apache_config/node.rb', line 9 def [] name r = Array(children).select { |child| child.name.downcase == name.downcase } case r.size when 0 self << Node.new(name) when 1 r.first else r end end |
#hasChildren? ⇒ Boolean
33 34 35 |
# File 'lib/apache_config/node.rb', line 33 def hasChildren? children && children.any? end |
#isRoot? ⇒ Boolean
29 30 31 |
# File 'lib/apache_config/node.rb', line 29 def isRoot? parent.nil? end |