class HamlLint::Tree::Node::Siblings
Finds the node's siblings within the tree and makes them queryable.
Public Instance Methods
next(node)
click to toggle source
Finds the next sibling in the tree for a given node.
@param node [HamlLint::Tree::Node] @return [HamlLint::Tree::Node, nil]
# File lib/haml_lint/tree/node.rb, line 184 def next(node) subsequents(node).first end
previous(node)
click to toggle source
Finds the previous sibling in the tree for a given node.
@param node [HamlLint::Tree::Node] @return [HamlLint::Tree::Node, nil]
# File lib/haml_lint/tree/node.rb, line 192 def previous(node) priors(node).last end
priors(node)
click to toggle source
Finds all sibling notes that appear before a node in the tree.
@param node [HamlLint::Tree::Node] @return [Array<HamlLint::Tree::Node>]
# File lib/haml_lint/tree/node.rb, line 200 def priors(node) position = position(node) if position.zero? [] else siblings[0..(position - 1)] end end
subsequents(node)
click to toggle source
Finds all sibling notes that appear after a node in the tree.
@param node [HamlLint::Tree::Node] @return [Array<HamlLint::Tree::Node>]
# File lib/haml_lint/tree/node.rb, line 213 def subsequents(node) siblings[(position(node) + 1)..-1] end
Private Instance Methods
position(node)
click to toggle source
Finds the position of a node within a set of siblings.
@api private @return [Integer, nil]
# File lib/haml_lint/tree/node.rb, line 229 def position(node) siblings.index(node) end