Class: LibXML::XML::XPath::Object
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Instance Chain:
self,
Enumerable
|
|
Inherits: | Object |
Defined in: | ext/libxml/ruby_xml_xpath_object.c, ext/libxml/ruby_xml_xpath_object.c |
Overview
A collection of nodes returned from the evaluation of an ::LibXML::XML::XPath
or XML::XPointer
expression.
Instance Attribute Summary
- #context readonly
-
#empty? ⇒ Boolean
readonly
Determine whether this nodeset is empty (contains no nodes).
Instance Method Summary
-
#[](i) ⇒ node
array index into set of nodes.
-
#debug ⇒ Boolean
Dump libxml debugging information to stdout.
-
#each {|node| ... } ⇒ self
Call the supplied block for each node in this set.
-
#first ⇒ node
Returns the first node in this node set, or nil if none exist.
-
#last ⇒ node
Returns the last node in this node set, or nil if none exist.
-
#length ⇒ Numeric
(also: #size)
Obtain the length of the nodesetval node list.
-
#size ⇒ Numeric
Alias for #length.
-
#string ⇒ String
Returns the original
::LibXML::XML::XPath
expression as a string. -
#to_a ⇒ Array, ...
Obtain an array of the nodes in this set.
-
#xpath_type ⇒ Integer
Returns the
::LibXML::XML::XPath
type of the result object.
Instance Attribute Details
#context (readonly)
[ GitHub ]
#empty? ⇒ Boolean
(readonly)
Determine whether this nodeset is empty (contains no nodes).
# File 'ext/libxml/ruby_xml_xpath_object.c', line 155
static VALUE rxml_xpath_object_empty_q(VALUE self) { rxml_xpath_object *rxpop; Data_Get_Struct(self, rxml_xpath_object, rxpop); if (rxpop->xpop->type != XPATH_NODESET) return Qnil; return (rxpop->xpop->nodesetval == NULL || rxpop->xpop->nodesetval->nodeNr <= 0) ? Qtrue : Qfalse; }
Instance Method Details
#[](i) ⇒ node
array index into set of nodes
# File 'ext/libxml/ruby_xml_xpath_object.c', line 230
static VALUE rxml_xpath_object_aref(VALUE self, VALUE aref) { rxml_xpath_object *rxpop; if (rxml_xpath_object_empty_q(self) == Qtrue) return Qnil; Data_Get_Struct(self, rxml_xpath_object, rxpop); return rxml_xpath_object_tabref(rxpop->xpop, NUM2INT(aref)); }
#debug ⇒ Boolean
Dump libxml debugging information to stdout. Requires Libxml be compiled with debugging enabled.
# File 'ext/libxml/ruby_xml_xpath_object.c', line 309
static VALUE rxml_xpath_object_debug(VALUE self) { #ifdef LIBXML_DEBUG_ENABLED rxml_xpath_object *rxpop; Data_Get_Struct(self, rxml_xpath_object, rxpop); xmlXPathDebugDumpObject(stdout, rxpop->xpop, 0); return Qtrue; #else rb_warn("libxml was compiled without debugging support."); return Qfalse; #endif }
#each {|node| ... } ⇒ self
Call the supplied block for each node in this set.
# File 'ext/libxml/ruby_xml_xpath_object.c', line 173
static VALUE rxml_xpath_object_each(VALUE self) { rxml_xpath_object *rxpop; int i; if (rxml_xpath_object_empty_q(self) == Qtrue) return Qnil; Data_Get_Struct(self, rxml_xpath_object, rxpop); for (i = 0; i < rxpop->xpop->nodesetval->nodeNr; i++) { rb_yield(rxml_xpath_object_tabref(rxpop->xpop, i)); } return (self); }
#first ⇒ node
Returns the first node in this node set, or nil if none exist.
# File 'ext/libxml/ruby_xml_xpath_object.c', line 196
static VALUE rxml_xpath_object_first(VALUE self) { rxml_xpath_object *rxpop; if (rxml_xpath_object_empty_q(self) == Qtrue) return Qnil; Data_Get_Struct(self, rxml_xpath_object, rxpop); return rxml_xpath_object_tabref(rxpop->xpop, 0); }
#last ⇒ node
Returns the last node in this node set, or nil if none exist.
# File 'ext/libxml/ruby_xml_xpath_object.c', line 213
static VALUE rxml_xpath_object_last(VALUE self) { rxml_xpath_object *rxpop; if (rxml_xpath_object_empty_q(self) == Qtrue) return Qnil; Data_Get_Struct(self, rxml_xpath_object, rxpop); return rxml_xpath_object_tabref(rxpop->xpop, -1); }
#length ⇒ Numeric
Also known as: #size
Obtain the length of the nodesetval node list.
# File 'ext/libxml/ruby_xml_xpath_object.c', line 247
static VALUE rxml_xpath_object_length(VALUE self) { rxml_xpath_object *rxpop; if (rxml_xpath_object_empty_q(self) == Qtrue) return INT2FIX(0); Data_Get_Struct(self, rxml_xpath_object, rxpop); return INT2NUM(rxpop->xpop->nodesetval->nodeNr); }
#length ⇒ Numeric
#size ⇒ Numeric
Numeric
#size ⇒ Numeric
Alias for #length.
#string ⇒ String
Returns the original ::LibXML::XML::XPath
expression as a string.
# File 'ext/libxml/ruby_xml_xpath_object.c', line 290
static VALUE rxml_xpath_object_string(VALUE self) { rxml_xpath_object *rxpop; Data_Get_Struct(self, rxml_xpath_object, rxpop); if (rxpop->xpop->stringval == NULL) return Qnil; return rxml_new_cstr( rxpop->xpop->stringval, rxpop->xdoc->encoding); }
#to_a ⇒ Array
, ...
Obtain an array of the nodes in this set.
# File 'ext/libxml/ruby_xml_xpath_object.c', line 125
static VALUE rxml_xpath_object_to_a(VALUE self) { VALUE set_ary, nodeobj; rxml_xpath_object *rxpop; xmlXPathObjectPtr xpop; int i; Data_Get_Struct(self, rxml_xpath_object, rxpop); xpop = rxpop->xpop; set_ary = rb_ary_new(); if (!((xpop->nodesetval == NULL) || (xpop->nodesetval->nodeNr == 0))) { for (i = 0; i < xpop->nodesetval->nodeNr; i++) { nodeobj = rxml_xpath_object_tabref(xpop, i); rb_ary_push(set_ary, nodeobj); } } return (set_ary); }
#xpath_type ⇒ Integer
Returns the ::LibXML::XML::XPath
type of the result object. Possible values are defined as constants on the ::LibXML::XML::XPath
class and include:
# File 'ext/libxml/ruby_xml_xpath_object.c', line 277
static VALUE rxml_xpath_object_get_type(VALUE self) { rxml_xpath_object *rxpop; Data_Get_Struct(self, rxml_xpath_object, rxpop); return INT2FIX(rxpop->xpop->type); }