Class: Paru::Selector
- Inherits:
-
Object
- Object
- Paru::Selector
- 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
"*"
- PSEUDO_SELECTORS =
All pseudo selectors
[ANY_SELECTOR]
Instance Method Summary collapse
-
#initialize(selector) ⇒ Selector
constructor
Create a new Selector based on the selector string.
-
#matches?(node, filtered_nodes) ⇒ Boolean
Does node get selected by this Selector in the context of the already filtered nodes?.
Constructor Details
#initialize(selector) ⇒ Selector
Create a new Selector based on the selector string
44 45 46 47 48 |
# File 'lib/paru/selector.rb', line 44 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?
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/paru/selector.rb', line 59 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 |