Class: RDF::N3::Algebra::Time::InSeconds
- Inherits:
-
ResourceOperator
- Object
- SPARQL::Algebra::Operator::Binary
- ResourceOperator
- RDF::N3::Algebra::Time::InSeconds
- Defined in:
- lib/rdf/n3/algebra/time/in_seconds.rb
Overview
Iff the subject is a xsd:dateTime
and the object is the integer number of seconds since the beginning of the era on a given system. Don’t assume a particular value, always test for it. The object can be calculated as a function of the subject.
Constant Summary collapse
Instance Attribute Summary
Attributes included from Enumerable
Instance Method Summary collapse
-
#input_operand ⇒ RDF::Term
Return both subject and object operands.
-
#resolve(resource, position:) ⇒ RDF::Term
The time:inseconds operator takes may have either a bound subject or object.
-
#valid?(subject, object) ⇒ Boolean
Either subject or object must be a bound resource.
Methods inherited from ResourceOperator
Methods included from Builtin
#each, #evaluate, #hash, #rank, #to_uri
Instance Method Details
#input_operand ⇒ RDF::Term
Return both subject and object operands.
54 55 56 |
# File 'lib/rdf/n3/algebra/time/in_seconds.rb', line 54 def input_operand RDF::N3::List.new(values: operands) end |
#resolve(resource, position:) ⇒ RDF::Term
The time:inseconds operator takes may have either a bound subject or object.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rdf/n3/algebra/time/in_seconds.rb', line 17 def resolve(resource, position:) case position when :subject case resource when RDF::Query::Variable resource when RDF::Literal # Subject evaluates to seconds from the epoc RDF::Literal::Integer.new(resource.as_datetime.object.strftime("%s")) else nil end when :object case resource when RDF::Query::Variable resource when RDF::Literal resource = resource.as_number # Object evaluates to the DateTime representation of the seconds form the epoc RDF::Literal(RDF::Literal::DateTime.new(::Time.at(resource).utc.to_datetime).to_s) else nil end end end |
#valid?(subject, object) ⇒ Boolean
Either subject or object must be a bound resource
44 45 46 47 48 |
# File 'lib/rdf/n3/algebra/time/in_seconds.rb', line 44 def valid?(subject, object) return true if subject.literal? || object.literal? log_error(NAME) {"subject or object are not literals: #{subject.inspect}, #{object.inspect}"} false end |