XSD::NSDBase
Module function
# File soap/baseData.rb, line 902
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
# File soap/baseData.rb, line 706
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
# File soap/baseData.rb, line 728
def [](*idxary)
if idxary.size != @rank
raise ArgumentError.new("given #{idxary.size} params does not match rank: #{@rank}")
end
retrieve(idxary)
end
# File soap/baseData.rb, line 736
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
# File soap/baseData.rb, line 724
def add(value)
self[*(@offset)] = value
end
# File soap/baseData.rb, line 786
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
# File soap/baseData.rb, line 770
def each
@data.each do |data|
yield(data)
end
end
# File soap/baseData.rb, line 798
def include?(var)
traverse_data(@data) do |v, *rank|
if v.is_a?(SOAPBasetype) && v.data == var
return true
end
end
false
end
# File soap/baseData.rb, line 719
def offset=(var)
@offset = var
@sparse = true
end
# File soap/baseData.rb, line 780
def replace
@data = deep_map(@data) do |ele|
yield(ele)
end
end
# File soap/baseData.rb, line 817
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
Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.
If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.
If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.
If you want to help improve the Ruby documentation, please see Improve the docs, or visit Documenting-ruby.org.