Class: HamlLint::Tree::Node::Siblings

Inherits:
SimpleDelegator
  • Object
show all
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

Instance Method Details

#next(node) ⇒ HamlLint::Tree::Node?

Finds the next sibling in the tree for a given node.



149
150
151
# File 'lib/haml_lint/tree/node.rb', line 149

def next(node)
  subsequents(node).first
end

#previous(node) ⇒ HamlLint::Tree::Node?

Finds the previous sibling in the tree for a given node.



157
158
159
# File 'lib/haml_lint/tree/node.rb', line 157

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.



165
166
167
168
169
170
171
172
# File 'lib/haml_lint/tree/node.rb', line 165

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.



178
179
180
# File 'lib/haml_lint/tree/node.rb', line 178

def subsequents(node)
  siblings[(position(node) + 1)..-1]
end