Sha256: b6c745318d0f0206254e7d30a57077349a52c6b6bbab4fd74e6a88f433ad6c4d

Contents?: true

Size: 1.33 KB

Versions: 2

Compression:

Stored size: 1.33 KB

Contents

module SPARQL; module Algebra
  class Operator
    ##
    # The SPARQL logical `day` operator.
    #
    # [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

      ##
      # Returns the day part of `arg` as an integer.
      #
      # @param  [RDF::Literal] operand
      #   the operand
      # @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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sparql-3.2.1 lib/sparql/algebra/operator/day.rb
sparql-3.2.0 lib/sparql/algebra/operator/day.rb