Class: RDF::Literal::DayTimeDuration

Inherits:
Duration show all
Defined in:
vendor/bundler/ruby/3.3.0/bundler/gems/rdf-xsd-1663b6f0e598/lib/rdf/xsd/duration.rb

Overview

A DayTimeDuration literal.

dayTimeDuration is a datatype ·derived· from duration by restricting its ·lexical representations· to instances of dayTimeDurationLexicalRep. The ·value space· of dayTimeDuration is therefore that of duration restricted to those whose ·months· property is 0. This results in a duration datatype which is totally ordered.

Constant Summary collapse

DATATYPE =
RDF::XSD.dayTimeDuration
GRAMMAR =
%r(\A
  (?<si>-)?
  P(?:(?:(?:(?<da>\d+)D)
      )
      (?:T(?:(?:(?:(?<hr>\d+)H)(?:(?<mi>\d+)M)?(?<se>\d+(?:\.\d+)?S)?)
          |  (?:(?:(?<mi>\d+)M)(?:(?<se>\d+(?:\.\d+)?)S)?)
          |  (?:(?<se>\d+(?:\.\d+)?)S)
          )
      )?
   |(?:T(?:(?:(?:(?<hr>\d+)H)(?:(?<mi>\d+)M)?(?<se>\d+(?:\.\d+)?S)?)
        |  (?:(?:(?<mi>\d+)M)(?:(?<se>\d+(?:\.\d+)?)S)?)
        |   (?:(?<se>\d+(?:\.\d+)?)S)
        )
    )
   )
\z)x.freeze

Constants inherited from RDF::Literal

FALSE, TRUE, XSD_STRING, ZERO

Constants included from N3::Terminals

N3::Terminals::ANON, N3::Terminals::BASE, N3::Terminals::BLANK_NODE_LABEL, N3::Terminals::DECIMAL, N3::Terminals::DOUBLE, N3::Terminals::ECHAR, N3::Terminals::ESCAPE_CHAR4, N3::Terminals::ESCAPE_CHAR8, N3::Terminals::EXPONENT, N3::Terminals::INTEGER, N3::Terminals::IPLSTART, N3::Terminals::IRIREF, N3::Terminals::IRI_RANGE, N3::Terminals::LANGTAG, N3::Terminals::PERCENT, N3::Terminals::PLX, N3::Terminals::PNAME_LN, N3::Terminals::PNAME_NS, N3::Terminals::PN_CHARS, N3::Terminals::PN_CHARS_BASE, N3::Terminals::PN_CHARS_BODY, N3::Terminals::PN_CHARS_U, N3::Terminals::PN_LOCAL, N3::Terminals::PN_LOCAL_BODY, N3::Terminals::PN_LOCAL_ESC, N3::Terminals::PN_PREFIX, N3::Terminals::PREFIX, N3::Terminals::QUICK_VAR_NAME, N3::Terminals::STRING_LITERAL_LONG_QUOTE, N3::Terminals::STRING_LITERAL_LONG_SINGLE_QUOTE, N3::Terminals::STRING_LITERAL_QUOTE, N3::Terminals::STRING_LITERAL_SINGLE_QUOTE, N3::Terminals::UCHAR, N3::Terminals::U_CHARS1, N3::Terminals::U_CHARS2, N3::Terminals::WS

Constants included from SPARQL::Algebra::Expression

SPARQL::Algebra::Expression::PATTERN_PARENTS

Constants included from Util::Logger

Util::Logger::IOWrapper

Instance Attribute Summary

Attributes inherited from RDF::Literal

#datatype, #direction, #language

Instance Method Summary collapse

Methods inherited from Duration

#==, #canonicalize!, #days, #hours, #humanize, #initialize, #minutes, #months, #plural, #seconds, #to_h, #to_s, #valid?, #years

Methods inherited from RDF::Literal

#==, #as_datetime, #as_number, #canonicalize!, #compatible?, #comperable_datatype2?, #comperable_datatype?, #datatype?, #direction?, #english?, #eql?, #escape, #hash, #humanize, #initialize, #inspect, #language?, #literal?, #method_missing, #object, #plain?, #respond_to_missing?, #simple?, #squish, #squish!, #to_s, #valid?, #valid_extended?, #validate!, #value, #value_hash

Methods included from Term

#==, #aggregate?, #as_datetime, #as_number, #compatible?, #eql?, #escape, #evaluate, #ndvars, #optimize, #sameTerm?, #term?, #terms, #to_base, #to_sparql, #to_term, #vars

Methods included from SPARQL::Algebra::Expression

cast, #constant?, #evaluate, extension, extension?, extensions, for, #invalid?, new, #node?, open, #optimize, #optimize!, parse, register_extension, #to_sxp_bin, #valid?, #validate!, #variable?

Methods included from Util::Logger

#log_debug, #log_depth, #log_error, #log_fatal, #log_info, #log_recover, #log_recovering?, #log_statistics, #log_warn, #logger

Methods included from Value

#anonymous?, #canonicalize, #canonicalize!, #constant?, #formula?, #graph?, #inspect, #inspect!, #invalid?, #iri?, #list?, #literal?, #node?, #resource?, #start_with?, #statement?, #term?, #to_ndvar, #to_nquads, #to_ntriples, #to_rdf, #to_term, #type_error, #uri?, #valid?, #validate!, #variable?

Constructor Details

This class inherits a constructor from RDF::Literal::Duration

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RDF::Literal

Instance Method Details

#*(other) ⇒ DayTimeDuration

Returns the result of multiplying the value of self by other. The result is rounded to the nearest month.

From the XQuery function op:multiply-dayTimeDuration.



421
422
423
424
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-xsd-1663b6f0e598/lib/rdf/xsd/duration.rb', line 421

def *(other)
  return type_error("#{other.inspect} is not a valid Numeric")  unless (other.is_a?(::Numeric) || other.is_a?(Literal::Numeric))
  self.class.new([0, object.last * other.to_f])
end

#+(other) ⇒ DayTimeDuration

Returns the sum of two xs:dayTimeDuration values.

From the XQuery function op:add-dayTimeDurations.



395
396
397
398
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-xsd-1663b6f0e598/lib/rdf/xsd/duration.rb', line 395

def +(other)
  return type_error("#{other.inspect} is not a valid DayTimeDuration") unless other.is_a?(Literal::DayTimeDuration) && other.valid?
  self.class.new([0, object.last + other.object.last])
end

#-(other) ⇒ DayTimeDuration

Returns the result of subtracting one xs:dayTimeDuration value from another.

From the XQuery function op:subtract-dayTimeDurationss.



408
409
410
411
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-xsd-1663b6f0e598/lib/rdf/xsd/duration.rb', line 408

def -(other)
  return type_error("#{other.inspect} is not a valid DayTimeDuration")  unless other.is_a?(Literal::DayTimeDuration) && other.valid?
  self.class.new([0, object.last - other.object.last])
end

#/(other) ⇒ DayTimeDuration, Decimal

Returns the result of dividing the value of self by other. The result is rounded to the nearest month.

From the XQuery functions op:divide-yearMonthDuration and op:divide-yearMonthDuration-by-yearMonthDuration.



435
436
437
438
439
440
441
442
443
444
445
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-xsd-1663b6f0e598/lib/rdf/xsd/duration.rb', line 435

def /(other)
  case other
  when DayTimeDuration
    return type_error("#{other.inspect} is not a valid DayTimeDuration or Numeric")  unless other.valid?
    Decimal.new(object.last / other.object.last.to_f)
  when Literal::Numeric, ::Numeric
    self.class.new([0, object.last / other.to_f])
  else
    type_error("#{other.inspect} is not a valid DayTimeDuration or Numeric") 
  end
end

#<=>(other) ⇒ Boolean

Compares this literal to other for sorting purposes.

From the XQuery function op:dayTimeDuration-less-than.



456
457
458
459
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-xsd-1663b6f0e598/lib/rdf/xsd/duration.rb', line 456

def <=>(other)
  return type_error("#{other.inspect} is not a valid DayTimeDuration") unless other.is_a?(Literal::DayTimeDuration) && other.valid?
  @object.last <=> other.object.last
end

#to_rRational

Converts the dayTimeDuration into rational seconds.

Returns:

  • (Rational)


465
466
467
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-xsd-1663b6f0e598/lib/rdf/xsd/duration.rb', line 465

def to_r
  Rational(object.last) / (24 * 3600)
end