In Files

  • soap/baseData.rb

Class/Module Index [+]

Quicksearch

SOAP::SOAPArray

Attributes

arytype[R]
offset[R]
rank[R]
size[RW]
size_fixed[RW]
sparse[RW]

Public Class Methods

decode(elename, type, arytype) click to toggle source

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
            
new(type = nil, rank = 1, arytype = nil) click to toggle source
 
               # 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
            

Public Instance Methods

[](*idxary) click to toggle source
 
               # 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
            
[]=(*idxary) click to toggle source
 
               # 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
            
add(value) click to toggle source
 
               # File soap/baseData.rb, line 724
def add(value)
  self[*(@offset)] = value
end
            
deep_map(ary, &block) click to toggle source
 
               # 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
            
each() click to toggle source
 
               # File soap/baseData.rb, line 770
def each
  @data.each do |data|
    yield(data)
  end
end
            
include?(var) click to toggle source
 
               # 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
            
offset=(var) click to toggle source
 
               # File soap/baseData.rb, line 719
def offset=(var)
  @offset = var
  @sparse = true
end
            
position() click to toggle source
 
               # File soap/baseData.rb, line 838
def position
  @position
end
            
replace() click to toggle source
 
               # File soap/baseData.rb, line 780
def replace
  @data = deep_map(@data) do |ele|
    yield(ele)
  end
end
            
soap2array(ary) click to toggle source
 
               # 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
            
to_a() click to toggle source
 
               # File soap/baseData.rb, line 776
def to_a
  @data.dup
end
            
traverse() click to toggle source
 
               # File soap/baseData.rb, line 807
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