Class: Nokolexbor::Attribute
Constant Summary
Constants inherited from Node
Node::ATTRIBUTE_NODE, Node::CDATA_SECTION_NODE, Node::COMMENT_NODE, Node::DOCUMENT_FRAG_NODE, Node::DOCUMENT_NODE, Node::DOCUMENT_TYPE_NODE, Node::ELEMENT_NODE, Node::ENTITY_NODE, Node::ENTITY_REF_NODE, Node::LOOKS_LIKE_XPATH, Node::NOTATION_NODE, Node::PI_NODE, Node::TEXT_NODE
Instance Attribute Summary
Attributes inherited from Node
Class Method Summary collapse
-
.new(document, name) ⇒ Attribute
Create a new Attribute on the
documentwithname.
Instance Method Summary collapse
- #inspect ⇒ Object
-
#name ⇒ String
(also: #node_name)
Get the name of the Attribute.
-
#name=(name) ⇒ String
(also: #node_name=)
Set the name of the Attribute.
-
#next ⇒ Attribute
Get the next Attribute.
-
#parent ⇒ Node
Get the owner Node of the Attribute.
-
#previous ⇒ Attribute
Get the previous Attribute.
-
#value ⇒ String
(also: #text, #content, #to_s, #to_str)
Get the value of the Attribute.
-
#value=(value) ⇒ String
Set the value of the Attribute.
Methods inherited from Node
#<<, #==, #[], #[]=, #add_child, #add_class, #add_next_sibling, #add_previous_sibling, #add_sibling, #after, #ancestors, #append_class, #at, #at_css, #at_css_impl, #at_xpath, #attribute, #attribute_nodes, #attributes, #attrs, #before, #cdata?, #child, #children, #children=, #classes, #clone, #comment?, #content=, #css, #css_impl, #css_path, #destroy, #document?, #each, #element?, #element_children, #first_element_child, #fragment, #fragment?, #inner_html, #key?, #keys, #kwattr_add, #kwattr_append, #kwattr_remove, #kwattr_values, #last_element_child, #matches?, #next_element, #node_type, #nokogiri_at_css, #nokogiri_css, #outer_html, #parent=, #parse, #path, #pointer_id, #prepend_child, #previous_element, #processing_instruction?, #remove, #remove_attr, #remove_class, #replace, #search, #source_location, #swap, #text?, #traverse, #value?, #values, #wrap, #write_to, #xpath
Class Method Details
.new(document, name) ⇒ Attribute
Create a new Attribute on the document with name.
16 17 18 19 20 21 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 47 48 49 50 51 52 |
# File 'ext/nokolexbor/nl_attribute.c', line 16
static VALUE
nl_attribute_new(int argc, VALUE *argv, VALUE klass)
{
lxb_dom_document_t *document;
VALUE rb_document;
VALUE rb_name;
VALUE rest;
rb_scan_args(argc, argv, "2*", &rb_document, &rb_name, &rest);
if (rb_obj_is_kind_of(rb_document, cNokolexborDocument)) {
document = nl_rb_document_unwrap(rb_document);
} else if (rb_obj_is_kind_of(rb_document, cNokolexborNode)) {
lxb_dom_node_t *node = nl_rb_node_unwrap(rb_document);
document = node->owner_document;
rb_document = nl_rb_document_get(rb_document);
} else {
rb_raise(rb_eArgError, "Expected a Document or Node, got %s", rb_class2name(CLASS_OF(rb_document)));
}
const char *c_name = StringValuePtr(rb_name);
size_t name_len = RSTRING_LEN(rb_name);
lxb_dom_attr_t *attr = lxb_dom_attr_interface_create(document);
if (attr == NULL) {
rb_raise(rb_eRuntimeError, "Error creating attribute");
}
lxb_dom_attr_set_name(attr, (const lxb_char_t *)c_name, name_len, false);
VALUE rb_node = nl_rb_node_create(&attr->node, rb_document);
if (rb_block_given_p()) {
rb_yield(rb_node);
}
return rb_node;
}
|
Instance Method Details
#inspect ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'ext/nokolexbor/nl_attribute.c', line 185
static VALUE
nl_attribute_inspect(VALUE self)
{
VALUE c = rb_class_name(CLASS_OF(self));
lxb_dom_node_t *node = nl_rb_node_unwrap(self);
lxb_dom_attr_t *attr = lxb_dom_interface_attr(node);
size_t len;
lxb_char_t *attr_value = lxb_dom_attr_value(attr, &len);
return rb_sprintf("#<%" PRIsVALUE " %s=\"%s\">", c,
lxb_dom_attr_qualified_name(attr, &len),
attr_value == NULL ? "" : (char *)attr_value);
}
|
#name ⇒ String Also known as: node_name
Get the name of the Attribute.
59 60 61 62 63 64 65 66 67 68 69 |
# File 'ext/nokolexbor/nl_attribute.c', line 59
static VALUE
nl_attribute_name(VALUE self)
{
lxb_dom_node_t *node = nl_rb_node_unwrap(self);
lxb_dom_attr_t *attr = lxb_dom_interface_attr(node);
size_t len;
lxb_char_t *name = lxb_dom_attr_qualified_name(attr, &len);
return rb_utf8_str_new(name, len);
}
|
#name=(name) ⇒ String Also known as: node_name=
Set the name of the Attribute.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'ext/nokolexbor/nl_attribute.c', line 77
static VALUE
nl_attribute_set_name(VALUE self, VALUE rb_name)
{
lxb_dom_node_t *node = nl_rb_node_unwrap(self);
lxb_dom_attr_t *attr = lxb_dom_interface_attr(node);
const char *c_name = StringValuePtr(rb_name);
size_t name_len = RSTRING_LEN(rb_name);
lxb_status_t status = lxb_dom_attr_set_name(attr, (const lxb_char_t *)c_name, name_len, false);
if (status != LXB_STATUS_OK) {
nl_raise_lexbor_error(status);
}
return rb_name;
}
|
#next ⇒ Attribute
Get the next Attribute.
173 174 175 176 177 178 179 180 181 182 183 |
# File 'ext/nokolexbor/nl_attribute.c', line 173
static VALUE
nl_attribute_next(VALUE self)
{
lxb_dom_node_t *node = nl_rb_node_unwrap(self);
lxb_dom_attr_t *attr = lxb_dom_interface_attr(node);
if (attr->next == NULL) {
return Qnil;
}
return nl_rb_node_create((lxb_dom_node_t *)attr->next, nl_rb_document_get(self));
}
|
#parent ⇒ Node
Get the owner Node of the Attribute.
139 140 141 142 143 144 145 146 147 148 149 |
# File 'ext/nokolexbor/nl_attribute.c', line 139
static VALUE
nl_attribute_parent(VALUE self)
{
lxb_dom_node_t *node = nl_rb_node_unwrap(self);
lxb_dom_attr_t *attr = lxb_dom_interface_attr(node);
if (attr->owner == NULL) {
return Qnil;
}
return nl_rb_node_create((lxb_dom_node_t *)attr->owner, nl_rb_document_get(self));
}
|
#previous ⇒ Attribute
Get the previous Attribute.
156 157 158 159 160 161 162 163 164 165 166 |
# File 'ext/nokolexbor/nl_attribute.c', line 156
static VALUE
nl_attribute_previous(VALUE self)
{
lxb_dom_node_t *node = nl_rb_node_unwrap(self);
lxb_dom_attr_t *attr = lxb_dom_interface_attr(node);
if (attr->prev == NULL) {
return Qnil;
}
return nl_rb_node_create((lxb_dom_node_t *)attr->prev, nl_rb_document_get(self));
}
|
#value ⇒ String Also known as: text, content, to_s, to_str
Get the value of the Attribute.
99 100 101 102 103 104 105 106 107 108 109 |
# File 'ext/nokolexbor/nl_attribute.c', line 99
static VALUE
nl_attribute_value(VALUE self)
{
lxb_dom_node_t *node = nl_rb_node_unwrap(self);
lxb_dom_attr_t *attr = lxb_dom_interface_attr(node);
size_t len;
lxb_char_t *value = lxb_dom_attr_value(attr, &len);
return rb_utf8_str_new(value, len);
}
|
#value=(value) ⇒ String
Set the value of the Attribute.
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'ext/nokolexbor/nl_attribute.c', line 117
static VALUE
nl_attribute_set_value(VALUE self, VALUE rb_content)
{
lxb_dom_node_t *node = nl_rb_node_unwrap(self);
lxb_dom_attr_t *attr = lxb_dom_interface_attr(node);
const char *c_content = StringValuePtr(rb_content);
size_t content_len = RSTRING_LEN(rb_content);
lxb_status_t status = lxb_dom_attr_set_value(attr, (const lxb_char_t *)c_content, content_len);
if (status != LXB_STATUS_OK) {
nl_raise_lexbor_error(status);
}
return rb_content;
}
|