Sha256: dcc52f00c9a1732d4cb848af5ee8a1f6bd14f3cc0b6fedf539ec21fe95f71e8f

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

module ShEx::Algebra
  ##
  class Stem < Operator::Unary
    NAME = :stem

    ##
    # Creates an operator instance from a parsed ShExJ representation
    # @param (see Operator#from_shexj)
    # @return [Operator]
    def self.from_shexj(operator, options = {})
      raise ArgumentError unless operator.is_a?(Hash) && operator['type'] == "Stem"
      raise ArgumentError, "missing stem in #{operator.inspect}" unless operator.has_key?('stem')
      super
    end

    ##
    # For a node n and constraint value v, nodeSatisfies(n, v) if n matches some valueSetValue vsv in v. A term matches a valueSetValue if:
    #
    # * vsv is a Stem with stem st and nodeIn(n, st).
    def match?(value, depth: 0)
      if value.start_with?(operands.first)
        status "matched #{value}", depth: depth
        true
      else
        status "not matched #{value}", depth: depth
        false
      end
    end

    def json_type
      # FIXME: This is funky, due to oddities in normative shexj
      parent.is_a?(Value) ? 'StemRange' : 'Stem'
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
shex-0.4.0 lib/shex/algebra/stem.rb
shex-0.3.0 lib/shex/algebra/stem.rb