class RDF::Literal::YearMonthDuration
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.
Constants
- DATATYPE
- GRAMMAR
Public Instance Methods
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](www.w3.org/TR/xpath-functions/#func-multiply-yearMonthDuration).
@param [Literal::Numeric, ::Numeric, DayTimeDuration] other @return [YearMonthDuration] @see www.w3.org/TR/xpath-functions/#func-multiply-yearMonthDuration
# 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
Returns the sum of two xs:yearMonthDuration values.
From the XQuery function [op:add-yearMonthDurations](www.w3.org/TR/xpath-functions/#func-add-yearMonthDurations).
@param [YearMonthDuration] other @return [YearMonthDuration] @see www.w3.org/TR/xpath-functions/#func-add-yearMonthDurations
# 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
Returns the result of subtracting one xs:yearMonthDuration value from another.
From the XQuery function [op:subtract-yearMonthDurations](www.w3.org/TR/xpath-functions/#func-subtract-yearMonthDurations).
@param [YearMonthDuration] other @return [YearMonthDuration] @see www.w3.org/TR/xpath-functions/#func-subtract-yearMonthDurations
# 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
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](www.w3.org/TR/xpath-functions/#func-divide-yearMonthDuration) and [op:divide-yearMonthDuration-by-yearMonthDuration](www.w3.org/TR/xpath-functions/#func-divide-yearMonthDuration-by-yearMonthDuration).
@param [Literal::Numeric, ::Numeric, YearMonthDuration] other @return [YearMonthDuration, Decimal] @see www.w3.org/TR/xpath-functions/#func-divide-yearMonthDuration @see www.w3.org/TR/xpath-functions/#func-divide-yearMonthDuration-by-yearMonthDuration
# 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
Compares this literal to ‘other` for sorting purposes.
From the XQuery function [op:yearMonthDuration-greater-than](www.w3.org/TR/xpath-functions/#func-yearMonthDuration-less-than).
@param [Literal::YearMonthDuration] other @return [Boolean] ‘true` if less than other for defined datatypes @see www.w3.org/TR/xpath-functions/#func-yearMonthDuration-less-than @see www.w3.org/TR/xpath-functions/#func-yearMonthDuration-greater-than
# 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
Converts the dayTimeDuration into rational seconds.
@return [Rational]
# File lib/rdf/xsd/duration.rb, line 357 def to_i object.first.to_i end