lib/sparql/algebra/operator/sha256.rb in sparql-3.1.8 vs lib/sparql/algebra/operator/sha256.rb in sparql-3.2.0

- old
+ new

@@ -5,11 +5,19 @@ ## # The SPARQL logical `sha256` operator. # # Returns the SHA256 checksum, as a hex digit string, calculated on the UTF-8 representation of the simple literal or lexical form of the `xsd:string`. Hex digits `SHOULD` be in lower case. # - # @example + # [121] BuiltInCall ::= ... | 'SHA256' '(' Expression ')' + # + # @example SPARQL Grammar + # PREFIX : <http://example.org/> + # SELECT (SHA256(?l) AS ?hash) WHERE { + # :s1 :str ?l + # } + # + # @example SSE # (prefix ((: <http://example.org/>)) # (project (?hash) # (extend ((?hash (sha256 ?l))) # (bgp (triple :s1 :str ?l))))) # @@ -28,9 +36,18 @@ # @raise [TypeError] if the operand is not a simple literal def apply(operand, **options) raise TypeError, "expected an RDF::Literal, but got #{operand.inspect}" unless operand.literal? raise TypeError, "expected simple literal or xsd:string, but got #{operand.inspect}" unless (operand.datatype || RDF::XSD.string) == RDF::XSD.string RDF::Literal(Digest::SHA256.new.hexdigest(operand.to_s)) + end + + ## + # + # Returns a partial SPARQL grammar for this operator. + # + # @return [String] + def to_sparql(**options) + "SHA256(" + operands.to_sparql(**options) + ")" end end # SHA256 end # Operator end; end # SPARQL::Algebra