Class: Paru::Selector

Inherits:
Object
  • Object
show all
Defined in:
lib/paru/selector.rb

Overview

A Selector models a relationship between Pandoc AST nodes, such as parent-child or sibling. Selectors in paru are like CSS selectors, but more limited because the Pandoc AST is quite simple.

Given a selector expression, Selector determines if a node complies with that selector expression or not.

Constant Summary collapse

ANY_SELECTOR =

Pseudo selector to select any inline and block node

'*'.freeze
PSEUDO_SELECTORS =

All pseudo selectors

[ANY_SELECTOR].freeze

Instance Method Summary collapse

Constructor Details

#initialize(selector) ⇒ Selector

Create a new Selector based on the selector string



45
46
47
48
49
# File 'lib/paru/selector.rb', line 45

def initialize(selector)
  @type = 'Unknown'
  @relations = []
  parse selector
end

Instance Method Details

#matches?(node, filtered_nodes) ⇒ Boolean

Does node get selected by this Selector in the context of the already filtered nodes?



60
61
62
63
64
65
66
67
68
69
# File 'lib/paru/selector.rb', line 60

def matches?(node, filtered_nodes)
  case @type
  when ANY_SELECTOR
    Paru::PANDOC_TYPES.include? node.type
  else
    node.type == @type and
      @classes.all? { |c| node.has_class? c } and
      @relations.all? { |r| r.matches? node, filtered_nodes }
  end
end