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.

Parameters:

Returns:



187
188
189
# File 'lib/haml_lint/tree/node.rb', line 187

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

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

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

Parameters:

Returns:



195
196
197
# File 'lib/haml_lint/tree/node.rb', line 195

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.

Parameters:

Returns:



203
204
205
206
207
208
209
210
# File 'lib/haml_lint/tree/node.rb', line 203

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.

Parameters:

Returns:



216
217
218
# File 'lib/haml_lint/tree/node.rb', line 216

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