Class: RDF::Literal::YearMonthDuration
- Inherits:
-
Duration
- Object
- RDF::Literal
- Duration
- RDF::Literal::YearMonthDuration
- Defined in:
- 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
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
otherfor 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
Constructor Details
This class inherits a constructor from RDF::Literal::Duration
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 '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 '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 '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 '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 '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 'lib/rdf/xsd/duration.rb', line 357 def to_i object.first.to_i end |