Sha256: 3e5563b63a048bbc05d7efab55b1e6ef2065496e4d252ce8da08128295254010

Contents?: true

Size: 921 Bytes

Versions: 5

Compression:

Stored size: 921 Bytes

Contents

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)))))
    #
    # @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)
        raise TypeError, "expected an RDF::Literal::DateTime, but got #{operand.inspect}" unless operand.is_a?(RDF::Literal::DateTime)
        RDF::Literal(operand.object.day)
      end
    end # Day
  end # Operator
end; end # SPARQL::Algebra

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sparql-3.1.6 lib/sparql/algebra/operator/day.rb
sparql-3.1.5 lib/sparql/algebra/operator/day.rb
sparql-3.1.4 lib/sparql/algebra/operator/day.rb
sparql-3.1.3 lib/sparql/algebra/operator/day.rb
sparql-3.1.2 lib/sparql/algebra/operator/day.rb