Class: Hpricot::Elem
- Defined in:
- lib/hpricot/tag.rb,
lib/hpricot/inspect.rb,
lib/hpricot/modules.rb,
lib/hpricot/modules.rb
Defined Under Namespace
Modules: Trav
Constant Summary
Constants included from Hpricot
AttrCore, AttrEvents, AttrFocus, AttrHAlign, AttrI18n, AttrVAlign, Attrs, ElementContent, ElementExclusions, ElementInclusions, FORM_TAGS, NamedCharacters, NamedCharactersPattern, OmittedAttrName, PREDEFINED, PREDEFINED_U, SELF_CLOSING_TAGS
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#etag ⇒ Object
Returns the value of attribute etag.
-
#stag ⇒ Object
Returns the value of attribute stag.
Instance Method Summary collapse
- #attributes ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(stag, children = nil, etag = nil) ⇒ Elem
constructor
A new instance of Elem.
- #output(out, opts = {}) ⇒ Object
- #pathname ⇒ Object
- #pretty_print(q) ⇒ Object
- #to_plain_text ⇒ Object
Methods included from Trav
#get_attribute, #has_attribute?, #remove_attribute, #set_attribute, #traverse_all_element, #traverse_some_element
Methods included from Container::Trav
#classes, #containers, #each_child, #each_child_with_index, #each_hyperlink, #each_hyperlink_uri, #each_uri, #filter, #find_element, #following_siblings, #get_element_by_id, #get_elements_by_tag_name, #insert_after, #insert_before, #next_sibling, #preceding_siblings, #previous_sibling, #replace_child, #siblings_at, #traverse_text_internal
Methods included from Traverse
#after, #at, #before, #bogusetag?, #children_of_type, #clean_path, #comment?, #css_path, #doc?, #doctype?, #elem?, filter, #following, #get_subnode, #html, #index, #inner_html=, #inner_text, #make, #next, #node_position, #nodes_at, #position, #preceding, #previous, #procins?, #search, #swap, #text?, #to_html, #to_original_html, #traverse_element, #traverse_text, #xmldecl?, #xpath
Methods included from Hpricot
XML, build, build_node, make, parse, scan, uxs, xchr, xs
Constructor Details
#initialize(stag, children = nil, etag = nil) ⇒ Elem
Returns a new instance of Elem.
51 52 53 54 |
# File 'lib/hpricot/tag.rb', line 51 def initialize(stag, children=nil, etag=nil) @stag, @etag = stag, etag @children = children ? children.each { |c| c.parent = self } : [] end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
50 51 52 |
# File 'lib/hpricot/tag.rb', line 50 def children @children end |
#etag ⇒ Object
Returns the value of attribute etag.
50 51 52 |
# File 'lib/hpricot/tag.rb', line 50 def etag @etag end |
#stag ⇒ Object
Returns the value of attribute stag.
50 51 52 |
# File 'lib/hpricot/tag.rb', line 50 def stag @stag end |
Instance Method Details
#attributes ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/hpricot/tag.rb', line 59 def attributes if raw_attributes raw_attributes.inject({}) do |hsh, (k, v)| hsh[k] = Hpricot.uxs(v) hsh end end end |
#empty? ⇒ Boolean
55 |
# File 'lib/hpricot/tag.rb', line 55 def empty?; @children.empty? end |
#output(out, opts = {}) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/hpricot/tag.rb', line 81 def output(out, opts = {}) if empty? and ElementContent[@stag.name] == :EMPTY @stag.output(out, opts.merge(:style => :empty)) else @stag.output(out, opts) @children.each { |n| n.output(out, opts) } if @etag @etag.output(out, opts) elsif !opts[:preserve] ETag.new(@stag.name).output(out, opts) end end out end |
#pathname ⇒ Object
80 |
# File 'lib/hpricot/tag.rb', line 80 def pathname; self.name end |
#pretty_print(q) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/hpricot/inspect.rb', line 20 def pretty_print(q) if empty? q.group(1, '{emptyelem', '}') { q.breakable; q.pp @stag } else q.group(1, "{elem", "}") { q.breakable; q.pp @stag if @children @children.each {|elt| q.breakable; q.pp elt } end if @etag q.breakable; q.pp @etag end } end end |
#to_plain_text ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/hpricot/tag.rb', line 67 def to_plain_text if self.name == 'br' "\n" elsif self.name == 'p' "\n\n" + super + "\n\n" elsif self.name == 'a' and self.has_attribute?('href') "#{super} [#{self['href']}]" elsif self.name == 'img' and self.has_attribute?('src') "[img:#{self['src']}]" else super end end |