Class: ShEx::Test

Inherits:
Object
  • Object
show all
Defined in:
lib/shex/extensions/test.rb

Instance Method Summary collapse

Instance Method Details

#visit(code: nil, matched: nil, depth: 0, **options) ⇒ Boolean

Called after a ShEx::TripleExpression has matched zero or more statements

Parameters:

  • code (String) (defaults to: nil)
  • matched (RDF::Statement) (defaults to: nil)

    statement

  • depth (Integer) (defaults to: 0)

    for logging

  • expression (ShEx::Algebra::TripleExpression)

    containing this semantic act

  • options (Hash{Symbol => Object})

    Other, operand-specific options

Returns:

  • (Boolean)

    Returning ‘false` results in NotSatisfied



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/shex/extensions/test.rb', line 11

def visit(code: nil, matched: nil, depth: 0, **options)
  str = if md = /^ *(fail|print) *\( *(?:(\"(?:[^\\"]|\\")*\")|([spo])) *\) *$/.match(code.to_s)
    md[2] || case md[3]
    when 's' then matched.subject
    when 'p' then matched.predicate
    when 'o' then matched.object
    else          matched.to_sxp
    end.to_s
  else
    matched ? matched.to_sxp : 'no statement'
  end

  $stdout.puts str
  return !md || md[1] == 'print'
end