Class: RDF::Literal::Time

Inherits:
Temporal show all
Defined in:
vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/literal/time.rb

Overview

A time literal.

The lexical representation for time is the left truncated lexical representation for xsd:dateTime: "hh:mm:ss.sss" with an optional following time zone indicator.

Constant Summary collapse

DATATYPE =

Since:

  • 0.2.1

RDF::URI("http://www.w3.org/2001/XMLSchema#time")
GRAMMAR =

Since:

  • 0.2.1

%r(\A((?:#{HOURFRAG}:#{MINUTEFRAG}:#{SECONDFRAG})|#{EODFRAG})(#{TZFRAG})?\z).freeze
FORMAT =

Since:

  • 0.2.1

'%H:%M:%S.%L'.freeze

Constants inherited from Temporal

RDF::Literal::Temporal::DAYFRAG, RDF::Literal::Temporal::EODFRAG, RDF::Literal::Temporal::HOURFRAG, RDF::Literal::Temporal::MINUTEFRAG, RDF::Literal::Temporal::MONTHFRAG, RDF::Literal::Temporal::SECONDFRAG, RDF::Literal::Temporal::TZFRAG, RDF::Literal::Temporal::YEARFRAG, RDF::Literal::Temporal::ZONE_GRAMMAR

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 Temporal

#+, #-, #<=>, #==, #adjust_to_timezone, #adjust_to_timezone!, #canonicalize!, #day, #hours, #milliseconds?, #minutes, #month, #seconds, #timezone, #timezone?, #to_s, #tz, #valid?, #year

Methods inherited from RDF::Literal

#<=>, #==, #as_datetime, #as_number, #canonicalize!, #compatible?, #comperable_datatype2?, #comperable_datatype?, #datatype?, #direction?, #english?, #eql?, #escape, #hash, #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

#initialize(value, datatype: nil, lexical: nil, **options) ⇒ Time

Internally, a DateTime is represented using a native ::DateTime. If initialized from a ::DateTime, the timezone is taken from that native object, otherwise, a timezone (or no timezone) is taken from the string representation having a matching zzzzzz component.

Parameters:

  • value (String, DateTime, #to_datetime)
  • value (Object)
  • direction (Symbol)

    (nil) Initial text direction.

  • language (Symbol)

    (nil) Language is downcased to ensure proper matching

  • lexical (String) (defaults to: nil)

    (nil) Supplied lexical representation of this literal, otherwise it comes from transforming value to a string form..

  • datatype (URI) (defaults to: nil)

    (nil)

  • validate (Boolean)

    (false)

  • canonicalize (Boolean)

    (false)

Since:

  • 0.2.1



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/literal/time.rb', line 23

def initialize(value, datatype: nil, lexical: nil, **options)
  @datatype = RDF::URI(datatype || self.class.const_get(:DATATYPE))
  @string   = lexical || (value if value.is_a?(String))
  @object   = case
    when value.respond_to?(:to_datetime)
      dt = value.to_datetime
      @zone = dt.zone
      # Normalize to 1972-12-31 dateTime base
      hms = dt.strftime(FORMAT)
      ::DateTime.parse("1972-12-31T#{hms}#{@zone}")
    else
      md = value.to_s.match(GRAMMAR)
      _, tm, tz = Array(md)
      if tz
        @zone = tz == 'Z' ? '+00:00' : tz
      else
        @zone = nil # No timezone
      end
      # Normalize 24:00:00 to 00:00:00
      hr, mi, se = tm.split(':')
      if hr.to_i > 23
        hr = "%.2i" % (hr.to_i % 24)
        @string = nil
      end
      value = "#{hr}:#{mi}:#{se}"
      # Normalize to 1972-12-31 dateTime base
      ::DateTime.parse("1972-12-31T#{hr}:#{mi}:#{se}#{@zone}")
  end rescue ::DateTime.new
end

Dynamic Method Handling

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

Instance Method Details

#humanize(lang = :en) ⇒ String

Returns a human-readable value for the literal

Returns:

Since:

  • 1.1.6



58
59
60
61
62
63
64
65
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/literal/time.rb', line 58

def humanize(lang = :en)
  t = object.strftime("%r")
  if timezone?
    z = @zone == '+00:00' ? "UTC" : @zone
    t += " #{z}"
  end
  t
end