Class WWW::Mechanize::Page::Link
In: lib/www/mechanize/page/link.rb
lib/www/mechanize/monkey_patch.rb
Parent: Object
Mechanize\n[lib/www/mechanize.rb\nlib/www/mechanize/content_type_error.rb\nlib/www/mechanize/cookie.rb\nlib/www/mechanize/cookie_jar.rb\nlib/www/mechanize/file.rb\nlib/www/mechanize/file_saver.rb\nlib/www/mechanize/form.rb\nlib/www/mechanize/form/button.rb\nlib/www/mechanize/form/check_box.rb\nlib/www/mechanize/form/field.rb\nlib/www/mechanize/form/file_upload.rb\nlib/www/mechanize/form/image_button.rb\nlib/www/mechanize/form/multi_select_list.rb\nlib/www/mechanize/form/option.rb\nlib/www/mechanize/form/radio_button.rb\nlib/www/mechanize/form/select_list.rb\nlib/www/mechanize/headers.rb\nlib/www/mechanize/history.rb\nlib/www/mechanize/list.rb\nlib/www/mechanize/monkey_patch.rb\nlib/www/mechanize/page.rb\nlib/www/mechanize/page/base.rb\nlib/www/mechanize/page/frame.rb\nlib/www/mechanize/page/link.rb\nlib/www/mechanize/page/meta.rb\nlib/www/mechanize/pluggable_parsers.rb\nlib/www/mechanize/response_code_error.rb\nlib/www/mechanize/unsupported_scheme_error.rb] lib/www/mechanize/headers.rb WWW dot/m_32_0.png

This class encapsulates links. It contains the text and the URI for ‘a’ tags parsed out of an HTML page. If the link contains an image, the alt text will be used for that image.

For example, the text for the following links with both be ‘Hello World’:

<a href="Hello">rubyforge.org">Hello World</a> <a href="rubyforge.org"> src="test.jpg" alt="Hello World"></a>

Methods

click   new   uri  

External Aliases

text -> to_s
page -> referer
pretty_inspect -> inspect

Attributes

attributes  [R] 
href  [R] 
node  [R] 
page  [R] 
text  [R] 

Public Class methods

[Source]

    # File lib/www/mechanize/page/link.rb, line 21
21:         def initialize(node, mech, page)
22:           @node = node
23:           @href = node['href'] 
24:           @text = node.inner_text
25:           @page = page
26:           @mech = mech
27:           @attributes = node
28: 
29:           # If there is no text, try to find an image and use it's alt text
30:           if (@text.nil? || @text.length == 0) && (node/'img').length > 0
31:             @text = ''
32:             (node/'img').each do |e|
33:               @text << ( e['alt'] || '')
34:             end
35:           end
36: 
37:         end

Public Instance methods

Click on this link

[Source]

    # File lib/www/mechanize/page/link.rb, line 44
44:         def click
45:           @mech.click self
46:         end

[Source]

    # File lib/www/mechanize/page/link.rb, line 39
39:         def uri
40:           URI.parse(@href)
41:         end

[Validate]