Class: SOAP::SOAPStruct

Inherits:
XSD::NSDBase show all
Includes:
Enumerable, SOAPCompoundtype
Defined in:
lib/soap/baseData.rb

Overview

Compound datatypes.

Direct Known Subclasses

RPC::SOAPMethod, SOAPBody, SOAPFault, SOAPHeader

Constant Summary

Constants included from SOAP

AttrActor, AttrActorName, AttrArrayType, AttrArrayTypeName, AttrEncodingStyle, AttrEncodingStyleName, AttrMustUnderstand, AttrMustUnderstandName, AttrOffset, AttrOffsetName, AttrPosition, AttrPositionName, AttrRoot, AttrRootName, Base64Literal, Charset, EleBody, EleBodyName, EleEnvelope, EleEnvelopeName, EleFault, EleFaultActor, EleFaultActorName, EleFaultCode, EleFaultCodeName, EleFaultDetail, EleFaultDetailName, EleFaultName, EleFaultString, EleFaultStringName, EleHeader, EleHeaderName, EncodingNamespace, EnvelopeNamespace, LiteralNamespace, MediaType, NS, NextActor, PropertyName, RPCRouter, RPCServerException, RPCUtils, SOAPNamespaceTag, SOAPProxy, TypeMap, VERSION, ValueArray, ValueArrayName, XSDNamespaceTag, XSINamespaceTag

Instance Attribute Summary

Attributes included from SOAPCompoundtype

#qualified

Attributes included from SOAPType

#definedtype, #elename, #encodingstyle, #extraattr, #id, #parent, #position, #precedents, #root

Attributes inherited from XSD::NSDBase

#type

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Enumerable

#inject

Methods included from SOAPType

#inspect, #rootnode

Methods inherited from XSD::NSDBase

inherited, #init, types

Constructor Details

#initialize(type = nil) ⇒ SOAPStruct

Returns a new instance of SOAPStruct.



443
444
445
446
447
448
# File 'lib/soap/baseData.rb', line 443

def initialize(type = nil)
  super()
  @type = type || XSD::QName::EMPTY
  @array = []
  @data = []
end

Class Method Details

.decode(elename, type) ⇒ Object



529
530
531
532
533
# File 'lib/soap/baseData.rb', line 529

def self.decode(elename, type)
  s = SOAPStruct.new(type)
  s.elename = elename
  s
end

Instance Method Details

#[](idx) ⇒ Object



462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
# File 'lib/soap/baseData.rb', line 462

def [](idx)
  if idx.is_a?(Range)
    @data[idx]
  elsif idx.is_a?(Integer)
    if (idx > @array.size)
      raise ArrayIndexOutOfBoundsError.new('In ' << @type.name)
    end
    @data[idx]
  else
    if @array.include?(idx)
	@data[@array.index(idx)]
    else
	nil
    end
  end
end

#[]=(idx, data) ⇒ Object



479
480
481
482
483
484
485
486
# File 'lib/soap/baseData.rb', line 479

def []=(idx, data)
  if @array.include?(idx)
    data.parent = self if data.respond_to?(:parent=)
    @data[@array.index(idx)] = data
  else
    add(idx, data)
  end
end

#add(name, value) ⇒ Object



458
459
460
# File 'lib/soap/baseData.rb', line 458

def add(name, value)
  add_member(name, value)
end

#eachObject



515
516
517
518
519
520
521
# File 'lib/soap/baseData.rb', line 515

def each
  idx = 0
  while idx < @array.length
    yield(@array[idx], @data[idx])
    idx += 1
  end
end

#key?(name) ⇒ Boolean

Returns:

  • (Boolean)


488
489
490
# File 'lib/soap/baseData.rb', line 488

def key?(name)
  @array.include?(name)
end

#membersObject



492
493
494
# File 'lib/soap/baseData.rb', line 492

def members
  @array
end

#replaceObject



523
524
525
526
527
# File 'lib/soap/baseData.rb', line 523

def replace
  members.each do |member|
    self[member] = yield(self[member])
  end
end

#to_objObject



496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
# File 'lib/soap/baseData.rb', line 496

def to_obj
  hash = {}
  proptype = {}
  each do |k, v|
    value = v.respond_to?(:to_obj) ? v.to_obj : v.to_s
    case proptype[k]
    when :single
      hash[k] = [hash[k], value]
      proptype[k] = :multi
    when :multi
      hash[k] << value
    else
      hash[k] = value
      proptype[k] = :single
    end
  end
  hash
end

#to_sObject



450
451
452
453
454
455
456
# File 'lib/soap/baseData.rb', line 450

def to_s()
  str = ''
  self.each do |key, data|
    str << "#{key}: #{data}\n"
  end
  str
end