Class: XMLService::I_Base

Inherits:
I_Meta
  • Object
show all
Defined in:
lib/xmlservice.rb

Overview


data types


Instance Method Summary collapse

Methods inherited from I_Meta

#add_user_accessor, #instance_variable_forward_get, #instance_variable_forward_set, #parse_diag_attr, #parse_output_attr, #parse_return_attr, #remove_user_accessor, #shortCut

Constructor Details

#initialize(*args) ⇒ I_Base

Returns a new instance of I_Base.



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/xmlservice.rb', line 168

def initialize *args
  case args.size
  when 0
    initialize_zero *args
  when 1
    initialize_doc *args
  when 2
    initialize_type2 *args
  when 3
    initialize_type3 *args
  when 4
    initialize_type4 *args
  when 5
    initialize_type5 *args
  when 6
    initialize_type6 *args
  when 7
    initialize_type7 *args
  else
    raise
  end
end

Instance Method Details

#check_enddo(v, hint) ⇒ Object



296
297
298
299
300
301
302
303
304
305
# File 'lib/xmlservice.rb', line 296

def check_enddo(v,hint)
  msg = "invalid enddo"
  if v == nil
  else
    if v.instance_of? String
    else
      raise "#{self.class.name} #{hint} #{msg}"
    end
  end
end

#check_nil(v, msg, hint) ⇒ Object



229
230
231
232
233
# File 'lib/xmlservice.rb', line 229

def check_nil(v,msg,hint)
  if v == nil
    raise "#{self.class.name} #{hint} #{msg}"
  end
end

#check_number(v) ⇒ Object



234
235
236
237
238
239
240
241
242
243
244
# File 'lib/xmlservice.rb', line 234

def check_number(v)
  answer = true
  begin
    if Float(v) != nil
      answer = true
    end
  rescue
      answer = false
  end
  answer
end

#check_prec(v, hint) ⇒ Object



276
277
278
279
280
281
282
283
# File 'lib/xmlservice.rb', line 276

def check_prec(v,hint)
  msg = "invalid prec"
  check_nil(v,msg,hint)
  data = v.to_i
  if data < 0 or !check_number(v)
    raise "#{self.class.name} #{hint} #{msg}"
  end
end

#check_size(v, hint) ⇒ Object



268
269
270
271
272
273
274
275
# File 'lib/xmlservice.rb', line 268

def check_size(v,hint)
  msg = "invalid size"
  check_nil(v,msg,hint)
  data = v.to_i
  if data < 1 or !check_number(v)
    raise "#{self.class.name} #{hint} #{msg}"
  end
end

#check_type(v, hint) ⇒ Object



253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/xmlservice.rb', line 253

def check_type(v,hint)
  msg = "invalid type"
  check_nil(v,msg,hint)
  case v
  when "a" 
  when "i"
  when "u" 
  when "f" 
  when "p" 
  when "z" 
  when "b" 
  else
    raise "#{self.class.name} #{hint} #{msg}"
  end
end

#check_var(v, hint) ⇒ Object



245
246
247
248
249
250
251
252
# File 'lib/xmlservice.rb', line 245

def check_var(v,hint)
  msg = "invalid var"
  check_nil(v,msg,hint)
  if v and v.instance_of? String
  else
    raise "#{self.class.name} #{hint} #{msg}"
  end
end

#check_vary(v, hint) ⇒ Object



284
285
286
287
288
289
290
291
292
293
294
295
# File 'lib/xmlservice.rb', line 284

def check_vary(v,hint)
  msg = "invalid vary"
  check_nil(v,msg,hint)
  if v == false
  else
    data = v.to_i
    if data == 2 or data == 4
    else
      raise "#{self.class.name} #{hint} #{msg}"
    end
  end
end

#dupFromUserValueObject



342
343
344
345
346
# File 'lib/xmlservice.rb', line 342

def dupFromUserValue
  if defined? xml_user_accessor and !@xml_user_accessor.nil? and !@xml_user_accessor.empty?
    @xml_data = instance_variable_get("@#{xml_user_accessor}")
  end
end

#dupToUserValueObject



337
338
339
340
341
# File 'lib/xmlservice.rb', line 337

def dupToUserValue
  if defined? xml_user_accessor and !@xml_user_accessor.nil? and !@xml_user_accessor.empty?
    instance_variable_set("@#{xml_user_accessor}", @xml_data)
  end
end

#initialize_doc(element) ⇒ Object



199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/xmlservice.rb', line 199

def initialize_doc(element)
  @xml_var  = element.attributes['var']
  @xml_vary = element.attributes['vary']
  @xml_enddo = element.attributes['enddo']
  type  = element.attributes['type']
  tp    = self.typeParse(type,@xml_var)
  @xml_type = tp['type']
  @xml_size = tp['size']
  @xml_prec = tp['prec']
  self.setValue(element.text)
  self.add_user_accessor(@xml_var,@xml_data)
end

#initialize_type2(v1, v2) ⇒ Object



211
212
213
# File 'lib/xmlservice.rb', line 211

def initialize_type2(v1,v2)
  raise "#{self.class.name}.new(#{v1},#{v2}) invalid number of parameters" 
end

#initialize_type3(v1, v2, v3) ⇒ Object



214
215
216
# File 'lib/xmlservice.rb', line 214

def initialize_type3(v1,v2,v3)
  raise "#{self.class.name}.new(#{v1},#{v2},#{v3}) invalid number of parameters" 
end

#initialize_type4(v1, v2, v3, v4) ⇒ Object



217
218
219
# File 'lib/xmlservice.rb', line 217

def initialize_type4(v1,v2,v3,v4)
  raise "#{self.class.name}.new(#{v1},#{v2},#{v3},#{v4}) invalid number of parameters" 
end

#initialize_type5(v1, v2, v3, v4, v5) ⇒ Object



220
221
222
# File 'lib/xmlservice.rb', line 220

def initialize_type5(v1,v2,v3,v4,v5)
  raise "#{self.class.name}.new(#{v1},#{v2},#{v3},#{v4},#{v5}) invalid number of parameters" 
end

#initialize_type6(v1, v2, v3, v4, v5, v6) ⇒ Object



223
224
225
# File 'lib/xmlservice.rb', line 223

def initialize_type6(v1,v2,v3,v4,v5,v6)
  raise "#{self.class.name}.new(#{v1},#{v2},#{v3},#{v4},#{v5},#{v6}) invalid number of parameters" 
end

#initialize_type7(v1, v2, v3, v4, v5, v6, v7) ⇒ Object



226
227
228
# File 'lib/xmlservice.rb', line 226

def initialize_type7(v1,v2,v3,v4,v5,v6,v7)
  self.initialize_value(v1,v2,v3,v4,v5,v6,v7,"(type=#{v1},size=#{v2},prec=#{v3},var=#{v4},varying=#{v5},data=#{v6},enddo=#{v6})")
end

#initialize_value(type, size, prec, var, vary, data, enddo, hint) ⇒ Object



306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# File 'lib/xmlservice.rb', line 306

def initialize_value(type,size,prec,var,vary,data,enddo,hint)
  check_type(type,hint)
  check_size(size,hint)
  check_prec(prec,hint)
  check_var(var,hint)
  check_vary(vary,hint)
  check_enddo(enddo,hint)
  @xml_type = type
  @xml_size = size 
  @xml_prec = prec 
  @xml_vary = vary
  @xml_var  = var
  @xml_enddo = enddo
  self.add_user_accessor(var,data)
  self.setValue(data)
end

#initialize_zeroObject



190
191
192
193
194
195
196
197
198
# File 'lib/xmlservice.rb', line 190

def initialize_zero
  @xml_type = nil
  @xml_size = nil
  @xml_prec = nil
  @xml_vary = nil
  @xml_var  = nil
  @xml_data = nil
  @xml_enddo = nil
end

#precisionObject



328
329
330
# File 'lib/xmlservice.rb', line 328

def precision
  @xml_prec
end

#setValue(data) ⇒ Object



347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
# File 'lib/xmlservice.rb', line 347

def setValue(data)
  if data == nil
    rdata = 0
    case @xml_type
    when "a"
      rdata = ""
    when "b"
      rdata = "00"
    end
  elsif data.is_a?(XMLService::I_Base)
    rdata = data.value
  else
    rdata = data
  end
  case @xml_type
  when "a" 
    @xml_data = String.new(rdata)
  when "i"
    @xml_data = rdata.to_i 
  when "u" 
    @xml_data = rdata.to_i 
  when "f" 
    @xml_data = rdata.to_f
  when "p" 
    @xml_data = rdata.to_f
  when "z" 
    @xml_data = rdata.to_f
  when "b" 
    @xml_data = rdata
  end
  dupToUserValue
end

#sizeObject



325
326
327
# File 'lib/xmlservice.rb', line 325

def size
  @xml_size
end

#to_fObject



416
417
418
419
420
# File 'lib/xmlservice.rb', line 416

def to_f
  dupFromUserValue
  data = @xml_data.to_f
  data
end

#to_iObject



421
422
423
424
425
# File 'lib/xmlservice.rb', line 421

def to_i
  dupFromUserValue
  data = @xml_data.to_i
  data
end

#to_sObject



411
412
413
414
415
# File 'lib/xmlservice.rb', line 411

def to_s
  dupFromUserValue
  data = @xml_data.to_s
  data
end

#to_xmlObject



426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
# File 'lib/xmlservice.rb', line 426

def to_xml
  dupFromUserValue
  xml = ""
  data = @xml_data.to_s
  enddo = ""
  if @xml_enddo
    enddo = " enddo='#{@xml_enddo}'"
  end
  vary = ""
  if @xml_vary
    vary = " varying='#{@xml_vary}'"
  end
  case @xml_type
  when "a" 
    xml = "<data var='#{@xml_var}' type='#{@xml_size}#{@xml_type}'#{vary}>#{data}</data>\n"
  when "i"
    if @xml_size < 2
      type = " type='3#{@xml_type}0'"
    elsif @xml_size < 4
      type = " type='5#{@xml_type}0'"
    elsif @xml_size < 8
      type = " type='10#{@xml_type}0'"
    else
      type = " type='20#{@xml_type}0'"
    end
    xml = "<data var='#{@xml_var}'#{type}#{enddo}>#{data}</data>\n"
  when "u" 
    if @xml_size < 2
      type = " type='3#{@xml_type}0'"
    elsif @xml_size < 4
      type = " type='5#{@xml_type}0'"
    elsif @xml_size < 8
      type = " type='10#{@xml_type}0'"
    else
      xml = " type='20#{@xml_type}0'"
    end
    xml = "<data var='#{@xml_var}'#{type}#{enddo}>#{data}</data>\n"
  when "f" 
    xml = "<data var='#{@xml_var}' type='#{@xml_size}#{@xml_type}#{@xml_prec}#{enddo}'>#{data}</data>\n"
  when "p" 
    xml = "<data var='#{@xml_var}' type='#{@xml_size}#{@xml_type}#{@xml_prec}#{enddo}'>#{data}</data>\n"
  when "z" 
    xml = "<data var='#{@xml_var}' type='#{@xml_size}#{@xml_type}#{@xml_prec}#{enddo}'>#{data}</data>\n"
  when "b" 
    xml = "<data var='#{@xml_var}' type='#{@xml_size}#{@xml_type}'>#{data}</data>\n"
  end
  xml
end

#typeObject



322
323
324
# File 'lib/xmlservice.rb', line 322

def type
  @xml_type
end

#typeParse(type, vary) ⇒ Object



474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
# File 'lib/xmlservice.rb', line 474

def typeParse(type, vary)
  tp = Hash.new
  tp['type'] = nil
  tp['vary'] = 0
  tp['size'] = 0
  tp['prec'] = 0
  if type.index('a')
    size = type.split('a')
    tp['type'] = "a"
    tp['size'] = size[0]
    if vary == 2
      tp['vary'] = 2
    elsif vary == 4
      tp['vary'] = 4
    else
    end
  elsif type.index('i')
    size = type.split('i')
    tp['type'] = "i"
    tp['size'] = size[0]
  elsif type.index('u')
    size = type.split('u')
    tp['type'] = "u"
    tp['size'] = size[0]
  elsif type.index('f')
    size = type.split('f')
    tp['type'] = "f"
    tp['size'] = size[0]
  elsif type.index('p')
    size = type.split('p')
    tp['type'] = "p"
    tp['size'] = size[0]
    tp['prec'] = size[1]
  elsif type.index('z')
    size = type.split('z')
    tp['type'] = "z"
    tp['size'] = size[0]
    tp['prec'] = size[1]
  elsif type.index('b')
    size = type.split('b')
    tp['type'] = "b"
    tp['size'] = size[0]
  end
  tp['prec'] = tp['prec'].to_i
  tp['size'] = tp['size'].to_i
  tp
end

#valueObject



379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
# File 'lib/xmlservice.rb', line 379

def value
  dupFromUserValue
  if @xml_data == nil
    @xml_data = 0
    case @xml_type
    when "a"
      @xml_data = ""
    when "b"
      @xml_data = "00"
    end
    dupToUserValue
  end
  case @xml_type
  when "a" 
    data = @xml_data.to_s
  when "i"
    data = @xml_data.to_i 
  when "u" 
    data = @xml_data.to_i 
  when "f" 
    data = @xml_data.to_f
  when "p" 
    data = @xml_data.to_f
  when "z" 
    data = @xml_data.to_f
  when "b" 
    data = @xml_data # .pack('H')
  else
    data = @xml_data
  end
  data
end

#varObject



334
335
336
# File 'lib/xmlservice.rb', line 334

def var
  @xml_var
end

#varyObject



331
332
333
# File 'lib/xmlservice.rb', line 331

def vary
  @xml_vary
end