Sha256: 630db87108ecbbbcd952f106f2551537f5f99378d25c4a8e98c90fd30d1b2d73

Contents?: true

Size: 984 Bytes

Versions: 11

Compression:

Stored size: 984 Bytes

Contents

module SPARQL; module Algebra
  class Operator
    ##
    # The SPARQL logical `year` operator.
    #
    # Returns the year part of `arg` as an integer.
    #
    # @example
    #     (prefix ((: <http://example.org/>))
    #       (project (?s ?x)
    #         (extend ((?x (year ?date)))
    #           (bgp (triple ?s :date ?date)))))
    #
    # @see http://www.w3.org/TR/sparql11-query/#func-year
    class Year < Operator::Unary
      include Evaluatable

      NAME = :year

      ##
      # Returns the year 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.year)
      end
    end # Year
  end # Operator
end; end # SPARQL::Algebra

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
sparql-3.1.0 lib/sparql/algebra/operator/year.rb
sparql-3.0.2 lib/sparql/algebra/operator/year.rb
sparql-3.0.1 lib/sparql/algebra/operator/year.rb
sparql-3.0.0 lib/sparql/algebra/operator/year.rb
sparql-2.2.2 lib/sparql/algebra/operator/year.rb
sparql-2.2.1 lib/sparql/algebra/operator/year.rb
sparql-2.2.0 lib/sparql/algebra/operator/year.rb
sparql-2.1.0 lib/sparql/algebra/operator/year.rb
sparql-2.0.0 lib/sparql/algebra/operator/year.rb
sparql-2.0.0.beta2 lib/sparql/algebra/operator/year.rb
sparql-2.0.0.beta1 lib/sparql/algebra/operator/year.rb