Sha256: 2ebb55cc0bb22ba5e5b31cef183718c9ff8fcd63a450e01196aa0b0dd55bc3ab

Contents?: true

Size: 1.64 KB

Versions: 28

Compression:

Stored size: 1.64 KB

Contents

module SPARQL; module Algebra
  class Operator
    ##
    # A SPARQL `contains` operator.
    #
    # @example
    #   (strends ?x ?y)
    #
    # @see http://www.w3.org/TR/sparql11-query/#func-strends
    # @see http://www.w3.org/TR/xpath-functions/#func-ends-with
    class StrEnds < Operator::Binary
      include Evaluatable

      NAME = :strends

      ##
      # The STRENDS function corresponds to the XPath fn:ends-with function. The arguments must be argument compatible otherwise an error is raised.
      # 
      # For such input pairs, the function returns true if the lexical form of arg1 ends with the lexical form of arg2, otherwise it returns false.
      #
      # @example
      #     strEnds("foobar", "bar") #=> true
      #     strEnds("foobar"@en, "bar"@en) #=> true
      #     strEnds("foobar"^^xsd:string, "bar"^^xsd:string) #=> true
      #     strEnds("foobar"^^xsd:string, "bar") #=> true
      #     strEnds("foobar", "bar"^^xsd:string) #=> true
      #     strEnds("foobar"@en, "bar") #=> true
      #     strEnds("foobar"@en, "bar"^^xsd:string) #=> true
      #
      # @param  [RDF::Literal] left
      #   a literal
      # @param  [RDF::Literal] right
      #   a literal
      # @return [RDF::Literal::Boolean]
      # @raise  [TypeError] if operands are not compatible
      def apply(left, right)
        case
        when !left.compatible?(right)
          raise TypeError, "expected two RDF::Literal operands, but got #{left.inspect} and #{right.inspect}"
        when left.to_s.end_with?(right.to_s) then RDF::Literal::TRUE
        else RDF::Literal::FALSE
        end
      end
    end # StrEnds
  end # Operator
end; end # SPARQL::Algebra

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
sparql-3.1.0 lib/sparql/algebra/operator/strends.rb
sparql-3.0.2 lib/sparql/algebra/operator/strends.rb
sparql-3.0.1 lib/sparql/algebra/operator/strends.rb
sparql-3.0.0 lib/sparql/algebra/operator/strends.rb
sparql-2.2.2 lib/sparql/algebra/operator/strends.rb
sparql-2.2.1 lib/sparql/algebra/operator/strends.rb
sparql-2.2.0 lib/sparql/algebra/operator/strends.rb
sparql-2.1.0 lib/sparql/algebra/operator/strends.rb
sparql-2.0.0 lib/sparql/algebra/operator/strends.rb
sparql-2.0.0.beta2 lib/sparql/algebra/operator/strends.rb
sparql-1.99.1 lib/sparql/algebra/operator/strends.rb
sparql-2.0.0.beta1 lib/sparql/algebra/operator/strends.rb
sparql-1.1.9.1 lib/sparql/algebra/operator/strends.rb
sparql-1.99.0 lib/sparql/algebra/operator/strends.rb
sparql-1.1.9 lib/sparql/algebra/operator/strends.rb
sparql-1.1.8 lib/sparql/algebra/operator/strends.rb
sparql-1.1.7 lib/sparql/algebra/operator/strends.rb
sparql-1.1.6 lib/sparql/algebra/operator/strends.rb
sparql-1.1.5 lib/sparql/algebra/operator/strends.rb
sparql-1.1.4 lib/sparql/algebra/operator/strends.rb