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:



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

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:



202
203
204
# File 'lib/haml_lint/tree/node.rb', line 202

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:



210
211
212
213
214
215
216
217
# File 'lib/haml_lint/tree/node.rb', line 210

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:



223
224
225
# File 'lib/haml_lint/tree/node.rb', line 223

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