Sha256: c36201da8e92180016383cd3fd15ca731a4067e96a9035b421353ece9a4ff39e
Contents?: true
Size: 1.09 KB
Versions: 5
Compression:
Stored size: 1.09 KB
Contents
module SPARQL; module Algebra class Operator ## # The SPARQL `strlen` operator. # # @example # (strlen ?x) # # @see https://www.w3.org/TR/sparql11-query/#func-strlen # @see https://www.w3.org/TR/xpath-functions/#func-string-length class StrLen < Operator::Unary include Evaluatable NAME = :strlen ## # The strlen function corresponds to the XPath fn:string-length function and returns an xsd:integer equal to the length in characters of the lexical form of the literal. # # @example # strlen("chat") 4 # strlen("chat"@en) 4 # strlen("chat"^^xsd:string) 4 # # @param [RDF::Literal] operand # the operand # @return [RDF::Literal::Integer] length of string # @raise [TypeError] if the operand is not a numeric value def apply(operand) raise TypeError, "expected a plain RDF::Literal, but got #{operand.inspect}" unless operand.literal? && operand.plain? RDF::Literal(operand.to_s.length) end end # StrLen end # Operator end; end # SPARQL::Algebra
Version data entries
5 entries across 5 versions & 1 rubygems