Sha256: 9884e658cfe60264a8fbacb3ebb5ae45768241a9981b9178e6ffbc190baa2625

Contents?: true

Size: 715 Bytes

Versions: 6

Compression:

Stored size: 715 Bytes

Contents

##
# Test extension.
#
# Default implementation of http://shex.io/extensions/Test/
#
# @see http://shex.io/extensions/Test/
require 'shex'

class ShEx::Test < ShEx::Extension("http://shex.io/extensions/Test/")
  # (see ShEx::Extension#visit)
  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
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
shex-0.6.0 lib/shex/extensions/test.rb
shex-0.5.2 lib/shex/extensions/test.rb
shex-0.5.1 lib/shex/extensions/test.rb
shex-0.5.0 lib/shex/extensions/test.rb
shex-0.4.0 lib/shex/extensions/test.rb
shex-0.3.0 lib/shex/extensions/test.rb