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

- old
+ new

@@ -1,16 +1,25 @@ module SPARQL; module Algebra class Operator ## # The SPARQL logical `day` operator. # - # @example - # (prefix ((: <http://example.org/>)) - # (project (?s ?x) - # (extend ((?x (day ?date))) - # (bgp (triple ?s :date ?date))))) + # [121] BuiltInCall ::= ... | 'DAY' '(' Expression ')' # + # @example SPARQL Grammar + # PREFIX : <http://example.org/> + # SELECT ?s (DAY(?date) AS ?x) WHERE { + # ?s :date ?date + # } + # + # @example SSE + # (prefix + # ((: <http://example.org/>)) + # (project (?s ?x) + # (extend ((?x (day ?date))) + # (bgp (triple ?s :date ?date))))) + # # @see https://www.w3.org/TR/sparql11-query/#func-day class Day < Operator::Unary include Evaluatable NAME = :day @@ -23,9 +32,18 @@ # @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) RDF::Literal(operand.object.day) + end + + ## + # + # Returns a partial SPARQL grammar for this operator. + # + # @return [String] + def to_sparql(**options) + "DAY(#{operands.last.to_sparql(**options)})" end end # Day end # Operator end; end # SPARQL::Algebra