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

- old
+ new

@@ -3,16 +3,25 @@ ## # The SPARQL logical `tz` operator. # # Returns the timezone part of `arg` as a simple literal. Returns the empty string if there is no timezone. # - # @example - # (prefix ((: <http://example.org/>)) - # (project (?s ?x) - # (extend ((?x (tz ?date))) - # (bgp (triple ?s :date ?date))))) + # [121] BuiltInCall ::= ... | 'TZ' '(' Expression ')' # + # @example SPARQL Grammar + # PREFIX : <http://example.org/> + # SELECT ?s (TZ(?date) AS ?x) WHERE { + # ?s :date ?date + # } + # + # @example SSE + # (prefix + # ((: <http://example.org/>)) + # (project (?s ?x) + # (extend ((?x (tz ?date))) + # (bgp (triple ?s :date ?date))))) + # # @see https://www.w3.org/TR/sparql11-query/#func-tz class TZ < Operator::Unary include Evaluatable NAME = :tz @@ -25,9 +34,17 @@ # @return [RDF::Literal] # @raise [TypeError] if the operand is not a simple literal def apply(operand, **options) raise TypeError, "expected an RDF::Literal::DateTime, but got #{operand.inspect}" unless operand.is_a?(RDF::Literal::DateTime) operand.tz + end + ## + # + # Returns a partial SPARQL grammar for this operator. + # + # @return [String] + def to_sparql(**options) + "TZ(" + operands.to_sparql(**options) + ")" end end # TZ end # Operator end; end # SPARQL::Algebra