class XSD::XSDDuration
Constants
- Type
Attributes
day[RW]
hour[RW]
min[RW]
month[RW]
sec[RW]
sign[RW]
year[RW]
Public Class Methods
new(value = nil)
click to toggle source
# File lib/xsd/datatypes.rb, line 447 def initialize(value = nil) init(Type, value) end
Private Instance Methods
_set(data)
click to toggle source
# File lib/xsd/datatypes.rb, line 472 def _set(data) if data.nil? @sign = @year = @month = @day = @hour = @min = @sec = @data = nil return end @sign, @year, @month, @day, @hour, @min, @sec = data @data = _to_s @data.freeze end
_to_s()
click to toggle source
# File lib/xsd/datatypes.rb, line 482 def _to_s str = '' str << @sign if @sign str << 'P' l = '' l << "#{ @year }Y" if @year.nonzero? l << "#{ @month }M" if @month.nonzero? l << "#{ @day }D" if @day.nonzero? r = '' r << "#{ @hour }H" if @hour.nonzero? r << "#{ @min }M" if @min.nonzero? r << "#{ @sec }S" if @sec.nonzero? str << l unless r.empty? str << "T" << r end if l.empty? and r.empty? str << "0D" end str end
screen_data(value)
click to toggle source
# File lib/xsd/datatypes.rb, line 453 def screen_data(value) /^([+\-]?)P(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)D)?(T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+(?:\.\d+)?)S)?)?$/ =~ value.to_s.strip unless Regexp.last_match raise ValueSpaceError.new("#{ type }: cannot accept '#{ value }'.") end if $5 and !$6 and !$7 and !$8 # allows durations lower than a day such as 'PT5S'. raise ValueSpaceError.new("#{ type }: cannot accept '#{ value }'.") end sign = $1 year = $2.to_i month = $3.to_i day = $4.to_i hour = $6.to_i min = $7.to_i sec = $8 ? XSDDecimal.new($8) : 0 [sign, year, month, day, hour, min, sec] end