| Class | Mechanize::Page::Link |
| In: |
lib/mechanize/page/link.rb
lib/mechanize/monkey_patch.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>
| text | -> | to_s |
| page | -> | referer |
| pretty_inspect | -> | inspect |
| attributes | [R] | |
| href | [R] | |
| node | [R] | |
| page | [R] | |
| text | [R] |
# File lib/mechanize/page/link.rb, line 20
20: def initialize(node, mech, page)
21: @node = node
22: @href = node['href']
23: @text = node.inner_text
24: @page = page
25: @mech = mech
26: @attributes = node
27:
28: # If there is no text, try to find an image and use it's alt text
29: if (@text.nil? || @text.length == 0) && node.search('img').length > 0
30: @text = ''
31: node.search('img').each do |e|
32: @text << ( e['alt'] || '')
33: end
34: end
35:
36: end