Sha256: 8aef7e1e2ef5969b85451a6cca53c71c3c707f2d1bffb0a324fa44eff23eef38

Contents?: true

Size: 1.24 KB

Versions: 2

Compression:

Stored size: 1.24 KB

Contents

module ShEx::Algebra
  ##
  class StemRange < Operator::Binary
    NAME = :stemRange

    ##
    # 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 StemRange with stem st and exclusions excls and nodeIn(n, st) and there is no x in excls such that nodeIn(n, excl).
    # * vsv is a Wildcard with exclusions excls and there is no x in excls such that nodeIn(n, excl).
    def match?(value)
      initial_match = case operands.first
      when :wildcard then true
      when RDF::Value then value.start_with?(operands.first)
      else false
      end

      unless initial_match
        status "#{value} does not match #{operands.first}"
        return false
      end

      if exclusions.any? do |exclusion|
          case exclusion
          when RDF::Value then value == exclusion
          when Stem       then exclusion.match?(value)
          else                 false
          end
        end
        status "#{value} excluded"
        return false
      end

      status "matched #{value}"
      true
    end

    def exclusions
      (operands.last.is_a?(Array) && operands.last.first == :exclusions) ? operands.last[1..-1] : []
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
shex-0.2.0 lib/shex/algebra/stem_range.rb
shex-0.1.0 lib/shex/algebra/stem_range.rb