Sha256: b4b5963b3b574cc587dbe8b9b61f20d858593c9298c34c7681108cd794c56f82

Contents?: true

Size: 804 Bytes

Versions: 1

Compression:

Stored size: 804 Bytes

Contents

module RDF::N3::Algebra::Time
  ##
  # For a date-time, its time:year is  the year component.
  #
  # @see https://www.w3.org/TR/xpath-functions/#func-year-from-dateTime
  class Year < RDF::N3::Algebra::ResourceOperator
    NAME = :timeYear
    URI = RDF::N3::Time.year

    ##
    # The time:year operator takes string or dateTime and extracts the year component.
    #
    # @param [RDF::Term] resource
    # @param [:subject, :object] position
    # @return [RDF::Term]
    # @see RDF::N3::ResourceOperator#evaluate
    def resolve(resource, position:)
      case position
      when :subject
        return nil unless resource.literal?
        resource.as_datetime.year
      when :object
        return nil unless resource.literal? || resource.variable?
        resource
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rdf-n3-3.3.0 lib/rdf/n3/algebra/time/year.rb