Class: RDF::N3::Algebra::Time::DayOfWeek

Inherits:
ResourceOperator
  • Object
show all
Defined in:
lib/rdf/n3/algebra/time/day_of_week.rb

Overview

For a date-time, its time:dayOfWeek is the the day number within the week, Sunday being 0.

Constant Summary collapse

NAME =
:timeDayOfWeek
URI =
RDF::N3::Time.dayOfWeek

Instance Attribute Summary

Attributes included from Enumerable

#existentials, #universals

Instance Method Summary collapse

Methods inherited from ResourceOperator

#as_literal, #execute, #input_operand, #valid?

Methods included from Builtin

#each, #evaluate, #hash, #input_operand, #rank, #to_uri

Instance Method Details

#resolve(resource, position:) ⇒ RDF::Term

The time:dayOfWeek operator takes string or dateTime and returns the 0-based day of the week.

Parameters:

  • resource (RDF::Term)
  • position (:subject, :object)

Returns:

See Also:

  • ResourceOperator#evaluate


15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rdf/n3/algebra/time/day_of_week.rb', line 15

def resolve(resource, position:)
  case position
  when :subject
    return nil unless resource.literal?
    resource = resource.as_datetime
    RDF::Literal(resource.object.strftime("%w").to_i)
  when :object
    return nil unless resource.literal? || resource.variable?
    resource
  end
end