### Home Classes Methods

### In Files

- lib/hpricot/modules.rb
- lib/hpricot/traverse.rb

### Methods

- #author
- #root
- #title

### Included Modules

- Hpricot::Container::Trav

### Files

- CHANGELOG
- COPYING

### Class/Module Index

Quicksearch

- Hpricot
- Hpricot::BlankSlate
- Hpricot::BogusETag::Trav
- Hpricot::Builder
- Hpricot::CData::Trav
- Hpricot::Comment::Trav
- Hpricot::Container
- Hpricot::Container::Trav
- Hpricot::Context
- Hpricot::CssProxy
- Hpricot::Doc::Trav
- Hpricot::DocType::Trav
- Hpricot::Elem::Trav
- Hpricot::EncodingError
- Hpricot::Error
- Hpricot::Leaf
- Hpricot::Leaf::Trav
- Hpricot::Name
- Hpricot::Node
- Hpricot::ProcIns::Trav
- Hpricot::Text::Trav
- Hpricot::Traverse
- Hpricot::XHTMLStrict
- Hpricot::XHTMLTransitional
- Hpricot::XMLDecl::Trav
- Kernel
- Object

No matching classes.

# Hpricot::Doc::Trav

### Public Instance Methods

author() click to toggle source

`author` searches author and return it as a text. It returns nil if not found.

`author` searchs following information.

- <meta name="author" content="author-name"> in HTML

- <link rev="made" title="author-name"> in HTML

- <dc:creator>author-name</dc:creator> in RSS

- <dc:publisher>author-name</dc:publisher> in RSS

    # File lib/hpricot/traverse.rb, line 761
    def author
      traverse_element('meta',
        '{http://www.w3.org/1999/xhtml}meta') {|e|
        begin
          next unless e.fetch_attr('name').downcase == 'author'
          author = e.fetch_attribute('content').strip
          return author if !author.empty?
        rescue IndexError
        end
      }

      traverse_element('link',
        '{http://www.w3.org/1999/xhtml}link') {|e|
        begin
          next unless e.fetch_attr('rev').downcase == 'made'
          author = e.fetch_attribute('title').strip
          return author if !author.empty?
        rescue IndexError
        end
      }

      if channel = find_element('{http://purl.org/rss/1.0/}channel')
        channel.traverse_element('{http://purl.org/dc/elements/1.1/}creator') {|e|
          begin
            author = e.extract_text.strip
            return author if !author.empty?
          rescue IndexError
          end
        }
        channel.traverse_element('{http://purl.org/dc/elements/1.1/}publisher') {|e|
          begin
            author = e.extract_text.strip
            return author if !author.empty?
          rescue IndexError
          end
        }
      end

      nil
    end

root() click to toggle source

    # File lib/hpricot/traverse.rb, line 805
    def root
      es = []
      children.each {|c| es << c if c.elem? } if children
      raise Hpricot::Error, "no element" if es.empty?
      raise Hpricot::Error, "multiple top elements" if 1 < es.length
      es[0]
    end

title() click to toggle source

`title` searches title and return it as a text. It returns nil if not found.

`title` searchs following information.

- <title>...</title> in HTML

- <title>...</title> in RSS

    # File lib/hpricot/traverse.rb, line 744
    def title
      e = find_element('title',
        '{http://www.w3.org/1999/xhtml}title',
        '{http://purl.org/rss/1.0/}title',
        '{http://my.netscape.com/rdf/simple/0.9/}title')
      e && e.extract_text
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.