Class: SOAP::SOAPElement

Inherits:
Object show all
Includes:
Enumerable
Defined in:
lib/soap/baseData.rb

Overview

SOAPElement is not typed so it is not derived from NSDBase.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Enumerable

#inject

Constructor Details

#initialize(elename, text = nil) ⇒ SOAPElement

Returns a new instance of SOAPElement.


521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
# File 'lib/soap/baseData.rb', line 521

def initialize(elename, text = nil)
  if !elename.is_a?(XSD::QName)
    elename = XSD::QName.new(nil, elename)
  end
  @encodingstyle = LiteralNamespace
  @elename = elename
  @id = nil
  @precedents = []
  @root = false
  @parent = nil
  @position = nil
  @extraattr = {}

  @qualified = nil

  @array = []
  @data = []
  @text = text
end

Instance Attribute Details

#elenameObject

Returns the value of attribute elename


511
512
513
# File 'lib/soap/baseData.rb', line 511

def elename
  @elename
end

#encodingstyleObject

Returns the value of attribute encodingstyle


509
510
511
# File 'lib/soap/baseData.rb', line 509

def encodingstyle
  @encodingstyle
end

#extraattrObject

Returns the value of attribute extraattr


517
518
519
# File 'lib/soap/baseData.rb', line 517

def extraattr
  @extraattr
end

#idObject

Returns the value of attribute id


512
513
514
# File 'lib/soap/baseData.rb', line 512

def id
  @id
end

#parentObject

Returns the value of attribute parent


515
516
517
# File 'lib/soap/baseData.rb', line 515

def parent
  @parent
end

#positionObject

Returns the value of attribute position


516
517
518
# File 'lib/soap/baseData.rb', line 516

def position
  @position
end

#precedentsObject (readonly)

Returns the value of attribute precedents


513
514
515
# File 'lib/soap/baseData.rb', line 513

def precedents
  @precedents
end

#qualifiedObject

Returns the value of attribute qualified


519
520
521
# File 'lib/soap/baseData.rb', line 519

def qualified
  @qualified
end

#rootObject

Returns the value of attribute root


514
515
516
# File 'lib/soap/baseData.rb', line 514

def root
  @root
end

#textObject Also known as: data

Text interface.


546
547
548
# File 'lib/soap/baseData.rb', line 546

def text
  @text
end

Class Method Details

.decode(elename) ⇒ Object


610
611
612
613
# File 'lib/soap/baseData.rb', line 610

def self.decode(elename)
  o = SOAPElement.new(elename)
  o
end

.from_obj(obj, namespace = nil) ⇒ Object


615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
# File 'lib/soap/baseData.rb', line 615

def self.from_obj(obj, namespace = nil)
  o = SOAPElement.new(nil)
  case obj
  when nil
    o.text = nil
  when Hash
    obj.each do |elename, value|
      if value.is_a?(Array)
        value.each do |subvalue|
          child = from_obj(subvalue, namespace)
          child.elename = to_elename(elename, namespace)
          o.add(child)
        end
      else
        child = from_obj(value, namespace)
        child.elename = to_elename(elename, namespace)
        o.add(child)
      end
    end
  else
    o.text = obj.to_s
  end
  o
end

.to_elename(obj, namespace = nil) ⇒ Object


640
641
642
643
644
645
646
647
648
# File 'lib/soap/baseData.rb', line 640

def self.to_elename(obj, namespace = nil)
  if obj.is_a?(XSD::QName)
    obj
  elsif /\A(.+):([^:]+)\z/ =~ obj.to_s
    XSD::QName.new($1, $2)
  else
    XSD::QName.new(namespace, obj.to_s)
  end
end

Instance Method Details

#[](idx) ⇒ Object


554
555
556
557
558
559
560
# File 'lib/soap/baseData.rb', line 554

def [](idx)
  if @array.include?(idx)
    @data[@array.index(idx)]
  else
    nil
  end
end

#[]=(idx, data) ⇒ Object


562
563
564
565
566
567
568
569
# File 'lib/soap/baseData.rb', line 562

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

#add(value) ⇒ Object

Element interfaces.


550
551
552
# File 'lib/soap/baseData.rb', line 550

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

#eachObject


602
603
604
605
606
607
608
# File 'lib/soap/baseData.rb', line 602

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

#inspectObject


541
542
543
# File 'lib/soap/baseData.rb', line 541

def inspect
  sprintf("#<%s:0x%x %s>", self.class.name, __id__, self.elename)
end

#key?(name) ⇒ Boolean

Returns:

  • (Boolean)

571
572
573
# File 'lib/soap/baseData.rb', line 571

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

#membersObject


575
576
577
# File 'lib/soap/baseData.rb', line 575

def members
  @array
end

#to_objObject


579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
# File 'lib/soap/baseData.rb', line 579

def to_obj
  if members.empty?
    @text
  else
    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
end