Class: Gumbo::Element

Inherits:
Node
  • Object
show all
Defined in:
ext/ruby_gumbo_ext.c,
lib/gumbo/element.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#parent, #parse_flags, #type

Instance Method Summary collapse

Methods inherited from Node

#dump_tree

Instance Attribute Details

#attributesObject (readonly)

#childrenObject (readonly)

#end_posObject (readonly)

#original_end_tagObject (readonly)

#original_end_tag_nameObject (readonly)

#original_tagObject (readonly)

#original_tag_nameObject (readonly)

#start_posObject (readonly)

#tagObject (readonly)

#tag_namespaceObject (readonly)

Instance Method Details

#attributeObject



26
# File 'ext/ruby_gumbo_ext.c', line 26

VALUE r_element_attribute(VALUE self, VALUE name);

#content_rangeObject

The byte offset range where the content inside this node exists, or nil if the node was inserted algorithmically, or has no content.



47
48
49
50
51
# 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?Boolean

Returns:

  • (Boolean)


27
# File 'ext/ruby_gumbo_ext.c', line 27

VALUE r_element_has_attribute(VALUE self, VALUE name);

#offset_rangeObject

The byte offset range where this element was extracted from, or nil if it was inserted algorithmically.



34
35
36
37
38
39
40
41
42
43
# 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_sObject Also known as: inspect



18
19
20
21
22
23
24
25
26
27
28
29
# 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