Class: SOAP::SOAPArray

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

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 collapse

Attributes included from SOAPCompoundtype

#qualified

Attributes included from SOAPType

#definedtype, #elename, #encodingstyle, #extraattr, #id, #parent, #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, rank = 1, arytype = nil) ⇒ SOAPArray

Returns a new instance of SOAPArray.


800
801
802
803
804
805
806
807
808
809
810
811
# File 'lib/soap/baseData.rb', line 800

def initialize(type = nil, rank = 1, arytype = nil)
  super()
  @type = type || ValueArrayName
  @rank = rank
  @data = Array.new
  @sparse = false
  @offset = Array.new(rank, 0)
  @size = Array.new(rank, 0)
  @size_fixed = false
  @position = nil
  @arytype = arytype
end

Instance Attribute Details

#arytypeObject (readonly)

Returns the value of attribute arytype


798
799
800
# File 'lib/soap/baseData.rb', line 798

def arytype
  @arytype
end

#offsetObject

Returns the value of attribute offset


796
797
798
# File 'lib/soap/baseData.rb', line 796

def offset
  @offset
end

#rankObject (readonly)

Returns the value of attribute rank


796
797
798
# File 'lib/soap/baseData.rb', line 796

def rank
  @rank
end

#sizeObject

Returns the value of attribute size


797
798
799
# File 'lib/soap/baseData.rb', line 797

def size
  @size
end

#size_fixedObject

Returns the value of attribute size_fixed


797
798
799
# File 'lib/soap/baseData.rb', line 797

def size_fixed
  @size_fixed
end

#sparseObject

Returns the value of attribute sparse


794
795
796
# File 'lib/soap/baseData.rb', line 794

def sparse
  @sparse
end

Class Method Details

.decode(elename, type, arytype) ⇒ Object


1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
# File 'lib/soap/baseData.rb', line 1000

def self.decode(elename, type, arytype)
  typestr, nofary = parse_type(arytype.name)
  rank = nofary.count(',') + 1
  plain_arytype = XSD::QName.new(arytype.namespace, typestr)
  o = SOAPArray.new(type, rank, plain_arytype)
  size = []
  nofary.split(',').each do |s|
    if s.empty?
	size.clear
	break
    else
	size << s.to_i
    end
  end
  unless size.empty?
    o.size = size
    o.size_fixed = true
  end
  o.elename = elename
  o
end

Instance Method Details

#[](*idxary) ⇒ Object


826
827
828
829
830
831
832
# File 'lib/soap/baseData.rb', line 826

def [](*idxary)
  if idxary.size != @rank
    raise ArgumentError.new("given #{idxary.size} params does not match rank: #{@rank}")
  end

  retrieve(idxary)
end

#[]=(*idxary) ⇒ Object


834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
# File 'lib/soap/baseData.rb', line 834

def []=(*idxary)
  value = idxary.slice!(-1)

  if idxary.size != @rank
    raise ArgumentError.new("given #{idxary.size} params(#{idxary})" +
      " does not match rank: #{@rank}")
  end

  idx = 0
  while idx < idxary.size
    if idxary[idx] + 1 > @size[idx]
	@size[idx] = idxary[idx] + 1
    end
    idx += 1
  end

  data = retrieve(idxary[0, idxary.size - 1])
  data[idxary.last] = value

  if value.is_a?(SOAPType)
    value.elename = ITEM_NAME
    # Sync type
    unless @type.name
	@type = XSD::QName.new(value.type.namespace,
 SOAPArray.create_arytype(value.type.name, @rank))
    end
    value.type ||= @type
  end

  @offset = idxary
  value.parent = self if value.respond_to?(:parent=)
  offsetnext
end

#add(value) ⇒ Object


818
819
820
# File 'lib/soap/baseData.rb', line 818

def add(value)
  self[*(@offset)] = value
end

#deep_map(ary, &block) ⇒ Object


884
885
886
887
888
889
890
891
892
893
894
# File 'lib/soap/baseData.rb', line 884

def deep_map(ary, &block)
  ary.collect do |ele|
    if ele.is_a?(Array)
	deep_map(ele, &block)
    else
	new_obj = block.call(ele)
	new_obj.elename = ITEM_NAME
	new_obj
    end
  end
end

#eachObject


868
869
870
871
872
# File 'lib/soap/baseData.rb', line 868

def each
  @data.each do |data|
    yield(data)
  end
end

#have_memberObject


822
823
824
# File 'lib/soap/baseData.rb', line 822

def have_member
  !@data.empty?
end

#include?(var) ⇒ Boolean

Returns:

  • (Boolean)

896
897
898
899
900
901
902
903
# File 'lib/soap/baseData.rb', line 896

def include?(var)
  traverse_data(@data) do |v, *rank|
    if v.is_a?(SOAPBasetype) && v.data == var
	return true
    end
  end
  false
end

#positionObject


936
937
938
# File 'lib/soap/baseData.rb', line 936

def position
  @position
end

#replaceObject


878
879
880
881
882
# File 'lib/soap/baseData.rb', line 878

def replace
  @data = deep_map(@data) do |ele|
    yield(ele)
  end
end

#soap2array(ary) ⇒ Object


915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
# File 'lib/soap/baseData.rb', line 915

def soap2array(ary)
  traverse_data(@data) do |v, *position|
    iteary = ary
    rank = 1
    while rank < position.size
	idx = position[rank - 1]
	if iteary[idx].nil?
 iteary = iteary[idx] = Array.new
	else
 iteary = iteary[idx]
	end
      rank += 1
    end
    if block_given?
	iteary[position.last] = yield(v)
    else
	iteary[position.last] = v
    end
  end
end

#to_aObject


874
875
876
# File 'lib/soap/baseData.rb', line 874

def to_a
  @data.dup
end

#traverseObject


905
906
907
908
909
910
911
912
913
# File 'lib/soap/baseData.rb', line 905

def traverse
  traverse_data(@data) do |v, *rank|
    unless @sparse
     yield(v)
    else
     yield(v, *rank) if v && !v.is_a?(SOAPNil)
    end
  end
end