Class: HamlLint::Tree::Node::Siblings
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- HamlLint::Tree::Node::Siblings
- Defined in:
- lib/haml_lint/tree/node.rb
Overview
Finds the node’s siblings within the tree and makes them queryable.
Instance Method Summary collapse
-
#next(node) ⇒ HamlLint::Tree::Node?
Finds the next sibling in the tree for a given node.
-
#previous(node) ⇒ HamlLint::Tree::Node?
Finds the previous sibling in the tree for a given node.
-
#priors(node) ⇒ Array<HamlLint::Tree::Node>
Finds all sibling notes that appear before a node in the tree.
-
#subsequents(node) ⇒ Array<HamlLint::Tree::Node>
Finds all sibling notes that appear after a node in the tree.
Instance Method Details
#next(node) ⇒ HamlLint::Tree::Node?
Finds the next sibling in the tree for a given node.
185 186 187 |
# File 'lib/haml_lint/tree/node.rb', line 185 def next(node) subsequents(node).first end |
#previous(node) ⇒ HamlLint::Tree::Node?
Finds the previous sibling in the tree for a given node.
193 194 195 |
# File 'lib/haml_lint/tree/node.rb', line 193 def previous(node) priors(node).last end |
#priors(node) ⇒ Array<HamlLint::Tree::Node>
Finds all sibling notes that appear before a node in the tree.
201 202 203 204 205 206 207 208 |
# File 'lib/haml_lint/tree/node.rb', line 201 def priors(node) position = position(node) if position.zero? [] else siblings[0..(position - 1)] end end |
#subsequents(node) ⇒ Array<HamlLint::Tree::Node>
Finds all sibling notes that appear after a node in the tree.
214 215 216 |
# File 'lib/haml_lint/tree/node.rb', line 214 def subsequents(node) siblings[(position(node) + 1)..-1] end |