Class XSD::XSDDuration
In: lib/xsd/datatypes.rb
Parent: XSDAnySimpleType

Methods

_set   _to_s   new   screen_data  

Constants

Type = QName.new(Namespace, DurationLiteral)

Attributes

day  [RW] 
hour  [RW] 
min  [RW] 
month  [RW] 
sec  [RW] 
sign  [RW] 
year  [RW] 

Public Class methods

[Source]

     # File lib/xsd/datatypes.rb, line 433
433:   def initialize(value = nil)
434:     init(Type, value)
435:   end

Private Instance methods

[Source]

     # File lib/xsd/datatypes.rb, line 458
458:   def _set(data)
459:     if data.nil?
460:       @sign = @year = @month = @day = @hour = @min = @sec = @data = nil
461:       return
462:     end
463:     @sign, @year, @month, @day, @hour, @min, @sec = data
464:     @data = _to_s
465:     @data.freeze
466:   end

[Source]

     # File lib/xsd/datatypes.rb, line 468
468:   def _to_s
469:     str = ''
470:     str << @sign if @sign
471:     str << 'P'
472:     l = ''
473:     l << "#{ @year }Y" if @year.nonzero?
474:     l << "#{ @month }M" if @month.nonzero?
475:     l << "#{ @day }D" if @day.nonzero?
476:     r = ''
477:     r << "#{ @hour }H" if @hour.nonzero?
478:     r << "#{ @min }M" if @min.nonzero?
479:     r << "#{ @sec }S" if @sec.nonzero?
480:     str << l
481:     if l.empty?
482:       str << "0D"
483:     end
484:     unless r.empty?
485:       str << "T" << r
486:     end
487:     str
488:   end

[Source]

     # File lib/xsd/datatypes.rb, line 439
439:   def screen_data(value)
440:     /^([+\-]?)P(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)D)?(T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+(?:\.\d+)?)S)?)?$/ =~ value.to_s.strip
441:     unless Regexp.last_match
442:       raise ValueSpaceError.new("#{ type }: cannot accept '#{ value }'.")
443:     end
444:     if ($5 and ((!$2 and !$3 and !$4) or (!$6 and !$7 and !$8)))
445:       # Should we allow 'PT5S' here?
446:       raise ValueSpaceError.new("#{ type }: cannot accept '#{ value }'.")
447:     end
448:     sign = $1
449:     year = $2.to_i
450:     month = $3.to_i
451:     day = $4.to_i
452:     hour = $6.to_i
453:     min = $7.to_i
454:     sec = $8 ? XSDDecimal.new($8) : 0
455:     [sign, year, month, day, hour, min, sec]
456:   end

[Validate]