Class: Xml::XmlDelegate
- Inherits:
-
Object
- Object
- Xml::XmlDelegate
- Includes:
- Enumerable
- Defined in:
- lib/r4x/xml_delegate.rb
Instance Method Summary collapse
- #add(nodes) ⇒ Object
- #add_in_scope_namespace__(namespace) ⇒ Object
- #attributes ⇒ Object
- #deep_copy ⇒ Object
- #default_value ⇒ Object
- #delete(key) ⇒ Object
- #delete_by_index(prop) ⇒ Object
- #descendents(prop) ⇒ Object
- #equals(value) ⇒ Object
- #get(prop) ⇒ Object
- #has_property ⇒ Object
-
#initialize(x) ⇒ XmlDelegate
constructor
A new instance of XmlDelegate.
- #insert(prop, value) ⇒ Object
- #klass ⇒ Object
- #name ⇒ Object
- #node ⇒ Object
- #parent ⇒ Object
- #put(prop, val) ⇒ Object
- #replace(prop, value) ⇒ Object
- #resolve_value ⇒ Object
- #text ⇒ Object
- #to_String ⇒ Object
-
#to_XmlList ⇒ Object
Conversions.
-
#to_XmlName ⇒ Object
def to_XmlList target_object = self.__parent__ target_poperty = self.__name__ l = XmlList.new(, target_object, target_property) end.
- #to_XmlString(ancestor_namespaces = nil, indent_level = nil) ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(x) ⇒ XmlDelegate
Returns a new instance of XmlDelegate.
8 9 10 |
# File 'lib/r4x/xml_delegate.rb', line 8 def initialize( x ) @x = x end |
Instance Method Details
#add(nodes) ⇒ Object
169 170 171 172 173 174 175 176 177 |
# File 'lib/r4x/xml_delegate.rb', line 169 def add( nodes ) case nodes when XmlList nodes.each { |n| @x.__node << n.__node } else @x.__node << nodes.__node end @x end |
#add_in_scope_namespace__(namespace) ⇒ Object
251 252 |
# File 'lib/r4x/xml_delegate.rb', line 251 def add_in_scope_namespace__(namespace) end |
#attributes ⇒ Object
18 |
# File 'lib/r4x/xml_delegate.rb', line 18 def attributes ; @x.__node.attributes ; end |
#deep_copy ⇒ Object
226 227 |
# File 'lib/r4x/xml_delegate.rb', line 226 def deep_copy end |
#default_value ⇒ Object
218 219 |
# File 'lib/r4x/xml_delegate.rb', line 218 def default_value end |
#delete(key) ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/r4x/xml_delegate.rb', line 180 def delete(prop) raise ArgumentError if Numeric === prop n = prop.self.to_XmlName if AttributeName === n attribs = attributes.collect{|a| if ((n.name.local_name == '*') or (n.name.local_name == a.name.local_name)) and ((n.name.uri == nil) or (n.name.uri == a.name.uri)) a.parent = nil nil else a end }.compact return true end dp = 0 (0...length).each { |q| if ((n.local_name == '*') or (@x[q].self.class == :element and @x[q].self.name.local_namespace == n.local_name)) and ((n.uri == nil) or (@x[q].self.class == :element and n.uri == @x[q].self.name.uri)) x[q].parent = nil x.delete_at(q) dp+=1 else if dp > 0 @x[q - dp] = x[q] @x.delete_at(q) end end } return true end |
#delete_by_index(prop) ⇒ Object
214 215 |
# File 'lib/r4x/xml_delegate.rb', line 214 def delete_by_index(prop) end |
#descendents(prop) ⇒ Object
230 231 |
# File 'lib/r4x/xml_delegate.rb', line 230 def descendents(prop) end |
#equals(value) ⇒ Object
234 235 |
# File 'lib/r4x/xml_delegate.rb', line 234 def equals(value) end |
#get(prop) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/r4x/xml_delegate.rb', line 22 def get(prop) if Integer === prop l = to_XmlList return l.__get__(prop) end n = prop.self.to_XmlName l = XmlList.new([],@x,n) if AttributeName === n @x.attributes.each { |a| if ( ( n.name.local_name =='*' || n.name.local_name == a.name.local_name ) and ( n.name.uri == nil || n.name.uri == a.name.uri ) ) l.append(a) end } return l end (0...length).each { |k| if ( (n.local_name == '*') or ((Element === @x[k]) and (@x[k].name.local_name == a.name.local_name)) ) and ( (n.uri == nil) or ((@x[k].__class__ == "element") and (n.uri == @x[k].name.uri)) ) l.append(@x[k]) end } return l end |
#has_property ⇒ Object
222 223 |
# File 'lib/r4x/xml_delegate.rb', line 222 def has_property end |
#insert(prop, value) ⇒ Object
243 244 |
# File 'lib/r4x/xml_delegate.rb', line 243 def insert(prop,value) end |
#klass ⇒ Object
16 |
# File 'lib/r4x/xml_delegate.rb', line 16 def klass ; @x.__class ; end |
#name ⇒ Object
13 |
# File 'lib/r4x/xml_delegate.rb', line 13 def name ; @x.__node.name ; end |
#node ⇒ Object
12 |
# File 'lib/r4x/xml_delegate.rb', line 12 def node ; @x.__node ; end |
#parent ⇒ Object
17 |
# File 'lib/r4x/xml_delegate.rb', line 17 def parent ; @x.__parent ; end |
#put(prop, val) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/r4x/xml_delegate.rb', line 86 def put( prop, val ) if !(Xml === val or XmlList === val) or ( [:text,:attribute].include?(val.self.class) ) c = val.to_s else c = val.self.deepcopy end raise ArgumentError if Numeric === prop return if [:text,:attribute,:comment,:instruction].include?( klass ) n = prop.to_XmlName default_namespace = get_default_namespace() if AttributeName === n return unless is_XmlName(n.self.name) if XmlList === c if c.length === 0 c = '' else #s = c[0].to_s #(1...c.length).each { |i| s += " #{c[i].to_s}" s = c.join(' ') end else c = c.to_s end a = nil x.attributes.each { |j| if (n.name.local_name == j.name.local_name) and (n.name.uri == nil or n.name.uri == j.name.uri) a = j unless a else x.delete(j.name) end } unless a unless n.name.uri nons = Namespace.new name = QName.new( nons, n.name ) else name = QName.new( n.name ) end a = Xml.new { |s| s.name=name ; s.classification=:attribute ; s.parent=x } x.attributes << a ns = name.get_namespace x.add_in_scope_namespace(ns) end a.value = c return end is_valid_name = is_XmlName(n) return if !is_valid_name and n.local_name != '*' i = nil primitive_assign = ((!(Xml === c or XmlList === c)) and n.local_name != '*') (x.length-1).downto(0) { |k| if ( (n.local_name == '*') or ( (@x[k].classification == :element) and (@x[k].name.locall_name == n.local_name) ) ) and ( (n.uri == nil) or ( (@x[k].classification==:element) and (n.uri == @x[k].name.uri) ) ) if i x.delete_by_index(i.to_s) i = k end end } unless i i = x.length if primitive_assign unless n.uri name = QName.new( default_namespace, n ) else name = QName.new(n) end y=Xml.new{|s| s.name=name; s.classification=:element; s.parent=x} ns=name.get_namespace x.replace(i.to_s,y) y.add_in_scope_namespace(ns) end end if primitive_asign # x[i].delete_all_properties s = c.to_s x[i].replace("0",s) if s != '' else x.replace(i.to_s,c) end return end |
#replace(prop, value) ⇒ Object
247 248 |
# File 'lib/r4x/xml_delegate.rb', line 247 def replace(prop,value) end |
#resolve_value ⇒ Object
238 239 240 |
# File 'lib/r4x/xml_delegate.rb', line 238 def resolve_value @x end |
#text ⇒ Object
14 |
# File 'lib/r4x/xml_delegate.rb', line 14 def text ; @x.__node.text ; end |
#to_String ⇒ Object
280 281 282 283 284 285 286 287 288 289 |
# File 'lib/r4x/xml_delegate.rb', line 280 def to_String return value if [:attribute, :text].include?(@x) if has_simple_content s = '' @x.each { |e| s << e unless [:comment,:instruction].include?(e.self.class) } return s else to_XmlString end end |
#to_XmlList ⇒ Object
Conversions
261 262 263 |
# File 'lib/r4x/xml_delegate.rb', line 261 def to_XmlList XmlList.new( @x ) end |
#to_XmlName ⇒ Object
def to_XmlList
target_object = self.__parent__
target_poperty = self.__name__
l = XmlList.new([self], target_object, target_property)
end
271 272 273 274 275 276 277 278 |
# File 'lib/r4x/xml_delegate.rb', line 271 def to_XmlName s = to_String if s =~ /^[_@]/ to_AttributeName( s.shift ) else QName.new(s) end end |
#to_XmlString(ancestor_namespaces = nil, indent_level = nil) ⇒ Object
291 292 293 |
# File 'lib/r4x/xml_delegate.rb', line 291 def to_XmlString( ancestor_namespaces=nil, indent_level=nil ) end |
#value ⇒ Object
19 |
# File 'lib/r4x/xml_delegate.rb', line 19 def value ; @x.__node.children.join('') ; end |