Class: Watobo::HTTP::Xml
- Inherits:
-
Object
- Object
- Watobo::HTTP::Xml
- Defined in:
- lib/watobo/http/xml/xml.rb
Defined Under Namespace
Modules: Mixin
Instance Method Summary collapse
- #has_parm?(parm_name) ⇒ Boolean
-
#initialize(root) ⇒ Xml
constructor
A new instance of Xml.
- #parameters(&block) ⇒ Object
- #set(parm) ⇒ Object
- #to_s ⇒ Object
Constructor Details
Instance Method Details
#has_parm?(parm_name) ⇒ Boolean
70 71 72 |
# File 'lib/watobo/http/xml/xml.rb', line 70 def has_parm?(parm_name) false end |
#parameters(&block) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/watobo/http/xml/xml.rb', line 74 def parameters(&block) params = [] return params unless @root.is_xml? leaf_nodes do |n| p = { :name => n.name } val = n.children.size == 0 ? "" : n.children.first.to_s p[:value] = val parent_name = "" unless n.parent.namespace.nil? parent_name << n.parent.namespace.prefix parent_name << ":" end parent_name << n.parent.name p[:parent] = "#{parent_name}" unless n.namespace.nil? p[:namespace] = n.namespace.prefix end param = XmlParameter.new(p) yield param if block_given? params << param end return params end |
#set(parm) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/watobo/http/xml/xml.rb', line 37 def set(parm) return false unless parm.location == :xml # puts "= set " # puts parm.to_yaml doc = Nokogiri::XML(@root.body.strip) namespaces = doc.collect_namespaces parent = doc.xpath("//#{parm.parent}", namespaces).first if parent.nil? puts "* could not find parent node #{parm.parent}" return false end parm_name = parm.namespace.nil? ? "" : parm.namespace parm_name << parm.name # find node node = parent.xpath("//#{parm_name}", namespaces).first if node.nil? puts "* node does not exist #{parm_name}" end child = node.children.first if child.nil? child = Nokogiri::XML::Text.new(parm.value, node) node.add_child child else child.content = parm.value end @root.set_body doc.to_s end |
#to_s ⇒ Object
33 34 35 |
# File 'lib/watobo/http/xml/xml.rb', line 33 def to_s s = @root.body.to_s end |