Class: RDF::Literal::YearMonthDuration
- Inherits:
-
Duration
- Object
- RDF::Literal
- Duration
- RDF::Literal::YearMonthDuration
- Defined in:
- vendor/bundler/ruby/3.3.0/bundler/gems/rdf-xsd-1663b6f0e598/lib/rdf/xsd/duration.rb
Overview
A YearMonthDuration
literal.
yearMonthDuration
is a datatype ·derived· from xsd:duration
by restricting its ·lexical representations· to instances of yearMonthDurationLexicalRep
. The ·value space· of yearMonthDuration
is therefore that of duration
restricted to those whose ·seconds· property is 0. This results in a duration
datatype which is totally ordered.
Constant Summary collapse
- DATATYPE =
RDF::XSD.yearMonthDuration
- GRAMMAR =
%r(\A (?<si>-)? P(?:(?:(?:(?:(?<yr>\d+)Y)(?:(?<mo>\d+)M)?) | (?:(?:(?<mo>\d+)M)) ) ) \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
Instance Attribute Summary
Attributes inherited from RDF::Literal
#datatype, #direction, #language
Instance Method Summary collapse
-
#*(other) ⇒ YearMonthDuration
Returns the result of multiplying the value of self by
other
. -
#+(other) ⇒ YearMonthDuration
Returns the sum of two xs:yearMonthDuration values.
-
#-(other) ⇒ YearMonthDuration
Returns the result of subtracting one xs:yearMonthDuration value from another.
-
#/(other) ⇒ YearMonthDuration, Decimal
Returns the result of dividing the value of self by
other
. -
#<=>(other) ⇒ Boolean
Compares this literal to
other
for sorting purposes. -
#to_i ⇒ Rational
Converts the dayTimeDuration into rational seconds.
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) ⇒ YearMonthDuration
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-yearMonthDuration.
313 314 315 316 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-xsd-1663b6f0e598/lib/rdf/xsd/duration.rb', line 313 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([(object.first * other.to_f).round, 0]) end |
#+(other) ⇒ YearMonthDuration
Returns the sum of two xs:yearMonthDuration values.
From the XQuery function op:add-yearMonthDurations.
287 288 289 290 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-xsd-1663b6f0e598/lib/rdf/xsd/duration.rb', line 287 def +(other) return type_error("#{other.inspect} is not a valid YearMonthDuration") unless other.is_a?(Literal::YearMonthDuration) && other.valid? self.class.new([object.first + other.object.first, 0]) end |
#-(other) ⇒ YearMonthDuration
Returns the result of subtracting one xs:yearMonthDuration value from another.
From the XQuery function op:subtract-yearMonthDurations.
300 301 302 303 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-xsd-1663b6f0e598/lib/rdf/xsd/duration.rb', line 300 def -(other) return type_error("#{other.inspect} is not a valid YearMonthDuration") unless other.is_a?(Literal::YearMonthDuration) && other.valid? self.class.new([object.first - other.object.first, 0]) end |
#/(other) ⇒ YearMonthDuration, 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.
327 328 329 330 331 332 333 334 335 336 337 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-xsd-1663b6f0e598/lib/rdf/xsd/duration.rb', line 327 def /(other) case other when Literal::YearMonthDuration return type_error("#{other.inspect} is not a valid YearMonthDuration or Numeric") unless other.valid? Decimal.new(object.first / other.object.first.to_f) when Literal::Numeric, ::Numeric self.class.new([(object.first / other.to_f).round, 0]) else type_error("#{other.inspect} is not a valid YearMonthDuration or Numeric") end end |
#<=>(other) ⇒ Boolean
Compares this literal to other
for sorting purposes.
From the XQuery function op:yearMonthDuration-greater-than.
348 349 350 351 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-xsd-1663b6f0e598/lib/rdf/xsd/duration.rb', line 348 def <=>(other) return type_error("#{other.inspect} is not a valid YearMonthDuration") unless other.is_a?(Literal::YearMonthDuration) && other.valid? @object.first <=> other.object.first end |
#to_i ⇒ Rational
Converts the dayTimeDuration into rational seconds.
357 358 359 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-xsd-1663b6f0e598/lib/rdf/xsd/duration.rb', line 357 def to_i object.first.to_i end |