Class: Handsoap::XmlQueryFront::REXMLDriver

Inherits:
Object
  • Object
show all
Includes:
XmlElement
Defined in:
lib/handsoap/xml_query_front.rb

Overview

Instance Method Summary collapse

Methods included from XmlElement

#/, #add_namespace, #assert_prefixes!, #initialize, #native_element, #to_big_decimal, #to_boolean, #to_date, #to_f, #to_i

Instance Method Details

#[](attribute_name) ⇒ Object

Raises:

  • (ArgumentError)


301
302
303
304
# File 'lib/handsoap/xml_query_front.rb', line 301

def [](attribute_name)
  raise ArgumentError.new unless attribute_name.kind_of? String
  @element.attributes[attribute_name]
end

#childrenObject



298
299
300
# File 'lib/handsoap/xml_query_front.rb', line 298

def children
  NodeSelection.new(@element.children.map{|node| REXMLDriver.new(node) })
end

#node_nameObject



278
279
280
281
282
283
284
# File 'lib/handsoap/xml_query_front.rb', line 278

def node_name
  if @element.respond_to? :name
    @element.name
  else
    @element.class.name.gsub(/.*::([^:]+)$/, "\\1").downcase
  end
end

#node_namespaceObject



285
286
287
288
289
290
291
# File 'lib/handsoap/xml_query_front.rb', line 285

def node_namespace
  if @element.respond_to? :namespace
    namespace = @element.namespace
    return if namespace == ''
  end
  namespace
end

#to_rawObject



313
314
315
# File 'lib/handsoap/xml_query_front.rb', line 313

def to_raw
  @element.to_s
end

#to_sObject



316
317
318
319
320
321
322
# File 'lib/handsoap/xml_query_front.rb', line 316

def to_s
  if @element.respond_to? :text
    @element.text
  else
    @element.value
  end
end

#to_xmlObject



305
306
307
308
309
310
311
312
# File 'lib/handsoap/xml_query_front.rb', line 305

def to_xml
  require 'rexml/formatters/pretty'
  formatter = REXML::Formatters::Pretty.new
  out = String.new
  formatter.write(@element, out)
  # patch for REXML's broken formatting
  out.gsub(/>\n\s+([^<]+)\n\s+<\//, ">\\1</")
end

#xpath(expression, ns = nil) ⇒ Object



292
293
294
295
296
297
# File 'lib/handsoap/xml_query_front.rb', line 292

def xpath(expression, ns = nil)
  ns = {} if ns.nil?
  ns = @namespaces.merge(ns)
  assert_prefixes!(expression, ns)
  NodeSelection.new(REXML::XPath.match(@element, expression, ns).map{|node| REXMLDriver.new(node, ns) })
end