class Gumbo::Element
Attributes
attributes[R]
children[R]
end_pos[R]
original_end_tag[R]
original_end_tag_name[R]
original_tag[R]
original_tag_name[R]
start_pos[R]
tag[R]
tag_namespace[R]
Public Instance Methods
attribute(name) → attribute
click to toggle source
If element
has an attribute with the name name
, return it. If not, return nil
.
VALUE r_element_attribute(VALUE self, VALUE name) { VALUE attributes; const char *name_str; name_str = StringValueCStr(name); attributes = rb_iv_get(self, "@attributes"); for (long i = 0; i < RARRAY_LEN(attributes); i++) { VALUE attribute; VALUE r_attr_name; const char *attr_name; attribute = rb_ary_entry(attributes, i); r_attr_name = rb_iv_get(attribute, "@name"); attr_name = StringValueCStr(r_attr_name); if (strcasecmp(attr_name, name_str) == 0) return attribute; } return Qnil; }
content_range()
click to toggle source
The byte offset range where the content inside this node exists, or nil if the node was inserted algorithmically, or has no content.
# File lib/gumbo/element.rb, line 47 def content_range return nil unless original_tag && original_end_tag (start_pos.offset + original_tag.bytesize)...end_pos.offset end
has_attribute?(name) → boolean
click to toggle source
Return true
if element
has an attribute with the name name
or false
else.
VALUE r_element_has_attribute(VALUE self, VALUE name) { VALUE attribute; attribute = r_element_attribute(self, name); return (attribute == Qnil) ? Qfalse : Qtrue; }
offset_range()
click to toggle source
The byte offset range where this element was extracted from, or nil if it was inserted algorithmically.
# File lib/gumbo/element.rb, line 34 def offset_range return nil unless original_tag if original_end_tag end_offset = end_pos.offset + original_end_tag.bytesize else end_offset = start_pos.offset + original_tag.bytesize end start_pos.offset...end_offset end
to_s()
click to toggle source
# File lib/gumbo/element.rb, line 18 def to_s if original_tag open_tag = original_tag end_tag = original_end_tag || '' else tag_name = original_tag_name || tag open_tag = "<#{tag_name}>" end_tag = "</#{tag_name}>" end open_tag + (children || []).map(&:to_s).join + end_tag end
Also aliased as: inspect