Module: Pdfrb::Arlington::Predicate::Functions::PresencePredicates

Defined in:
lib/pdfrb/arlington/predicate/functions/presence.rb

Overview

Presence predicates: IsRequired, IsPresent, NotPresent. These return Booleans.

Class Method Summary collapse

Class Method Details

.register_allObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/pdfrb/arlington/predicate/functions/presence.rb', line 12

def register_all
  Functions.register("IsRequired") do |args, ctx|
    # If a single predicate arg, evaluate its truthiness.
    # If no args, default to true.
    args.empty? ? true : !!args.first
  end

  Functions.register("IsPresent") do |args, ctx|
    next false if args.empty?

    key = args.first
    ctx.current && !ctx.current[key.to_sym].nil?
  end

  Functions.register("NotPresent") do |args, ctx|
    next true if args.empty?

    key = args.first
    ctx.current.nil? || ctx.current[key.to_sym].nil?
  end
end