Sha256: e81115b86dfcba244ca9a796f284e3faee336281b0681978d667a6c316459ea6

Contents?: true

Size: 1004 Bytes

Versions: 1

Compression:

Stored size: 1004 Bytes

Contents

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

    ##
    # The time:minute operator takes string or dateTime and extracts the minute 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.minutes
      when :object
        return nil unless resource.literal? || resource.variable?
        resource
      end
    end

    ##
    # There is no minute unless it was specified in the lexical form
    def valid?(subject, object)
      subject.value.match?(%r(^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}))
    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/minute.rb