Sha256: 3584a54a57182948cac597deb6fb5c221b4013e0cfdf6775b05d4c47c61f2aa2

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

module ShEx::Algebra
  ##
  class ShapeRef < Operator::Unary
    include Satisfiable
    NAME = :shapeRef

    def initialize(arg, **options)
      structure_error("Shape reference must be an IRI or BNode: #{arg}", exception: ArgumentError) unless arg.is_a?(RDF::Resource)
      super
    end

    ##
    # Satisfies method
    # @param [RDF::Resource] n
    # @return [Boolean] `true` if satisfied
    # @raise [ShEx::NotSatisfied] if not satisfied
    # @see [https://shexspec.github.io/spec/#shape-expression-semantics]
    def satisfies?(n)
      status "ref #{operands.first.to_s}"
      referenced_shape.satisfies?(n)
      status "ref satisfied"
      true
    rescue ShEx::NotSatisfied => e
      not_satisfied e.message
      raise
    end

    ##
    # Returns the referenced shape
    #
    # @return [Shape]
    def referenced_shape
      schema.shapes[operands.first.to_s]
    end

    ##
    # A ShapeRef is valid if it's ancestor schema has any shape with a lable
    # the same as it's reference.
    def validate!
      structure_error("Missing referenced shape: #{operands.first}") if referenced_shape.nil?
      # FIXME
      #raise ShEx::ParseError, "Self referencing shape: #{operands.first}" if referenced_shape == first_ancestor(Shape)
      super
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shex-0.1.0 lib/shex/algebra/shape_ref.rb