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

Methods

_set   _to_s   new   nonzero?   screen_data   screen_data_str  

Constants

Type = QName.new(Namespace, DecimalLiteral)

Public Class methods

[Source]

     # File lib/xsd/datatypes.rb, line 232
232:   def initialize(value = nil)
233:     init(Type, value)
234:   end

Public Instance methods

[Source]

     # File lib/xsd/datatypes.rb, line 236
236:   def nonzero?
237:     (@number != '0')
238:   end

Private Instance methods

[Source]

     # File lib/xsd/datatypes.rb, line 273
273:   def _set(data)
274:     if data.nil?
275:       @sign = @point = @number = @data = nil
276:       return
277:     end
278:     @sign, @point, @number = data
279:     @data = _to_s
280:     @data.freeze
281:   end

0.0 -> 0; right?

[Source]

     # File lib/xsd/datatypes.rb, line 284
284:   def _to_s
285:     str = @number.dup
286:     if @point.nonzero?
287:       str[@number.size + @point, 0] = '.'
288:     end
289:     @sign + str
290:   end

[Source]

     # File lib/xsd/datatypes.rb, line 242
242:   def screen_data(d)
243:     if d.is_a?(String)
244:       # Integer("00012") => 10 in Ruby.
245:       d.sub!(/^([+\-]?)0*(?=\d)/, "\\1")
246:     end
247:     screen_data_str(d)
248:   end

[Source]

     # File lib/xsd/datatypes.rb, line 250
250:   def screen_data_str(str)
251:     /^([+\-]?)(\d*)(?:\.(\d*)?)?$/ =~ str.to_s.strip
252:     unless Regexp.last_match
253:       raise ValueSpaceError.new("#{ type }: cannot accept '#{ str }'.")
254:     end
255:     sign = $1 || '+'
256:     int_part = $2
257:     frac_part = $3
258:     int_part = '0' if int_part.empty?
259:     frac_part = frac_part ? frac_part.sub(/0+$/, '') : ''
260:     point = - frac_part.size
261:     number = int_part + frac_part
262:     # normalize
263:     if sign == '+'
264:       sign = ''
265:     elsif sign == '-'
266:       if number == '0'
267:         sign = ''
268:       end
269:     end
270:     [sign, point, number]
271:   end

[Validate]