Class: Pdfrb::Arlington::Predicate::Evaluator
- Inherits:
-
Object
- Object
- Pdfrb::Arlington::Predicate::Evaluator
- Defined in:
- lib/pdfrb/arlington/predicate/evaluator.rb
Overview
Evaluates a predicate AST against a Context. Returns a Ruby value (typically Boolean for predicates; Integer/String for arithmetic helpers like ArrayLength, FileSize).
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Class Method Summary collapse
Instance Method Summary collapse
- #evaluate(node) ⇒ Object
-
#initialize(context) ⇒ Evaluator
constructor
A new instance of Evaluator.
Constructor Details
#initialize(context) ⇒ Evaluator
Returns a new instance of Evaluator.
12 13 14 |
# File 'lib/pdfrb/arlington/predicate/evaluator.rb', line 12 def initialize(context) @context = context end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
10 11 12 |
# File 'lib/pdfrb/arlington/predicate/evaluator.rb', line 10 def context @context end |
Class Method Details
.call(ast, context) ⇒ Object
16 17 18 |
# File 'lib/pdfrb/arlington/predicate/evaluator.rb', line 16 def self.call(ast, context) new(context).evaluate(ast) end |
Instance Method Details
#evaluate(node) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/pdfrb/arlington/predicate/evaluator.rb', line 20 def evaluate(node) return nil if node.nil? case node when AST::FunctionCall then dispatch_function(node) when AST::AtKey then resolve_at_key(node.name) when AST::PathExpr then resolve_path(node.segments) when AST::Literal then node.value when AST::ArrayLit then node.values when AST::BinOp then eval_binop(node) when AST::UnaryOp then eval_unaryop(node) when AST::LogicalOp then eval_logical(node) else raise Pdfrb::Error, "unknown AST node #{node.class}" end end |