Class | WWW::Mechanize::Page::Link |
In: |
lib/www/mechanize/monkey_patch.rb
lib/www/mechanize/page/link.rb |
Parent: | Object |
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>
pretty_inspect | -> | inspect |
text | -> | to_s |
page | -> | referer |
attributes | [R] | |
href | [R] | |
node | [R] | |
page | [R] | |
text | [R] |
# 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.search('img').length > 0 31: @text = '' 32: node.search('img').each do |e| 33: @text << ( e['alt'] || '') 34: end 35: end 36: 37: end