/usr/lib/ruby/1.8/mechanize/page/link.rb is in libwww-mechanize-ruby1.8 1.0.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | class Mechanize
class Page < Mechanize::File
# 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="http://rubyforge.org">Hello World</a>
# <a href="http://rubyforge.org"><img src="test.jpg" alt="Hello World"></a>
class Link
attr_reader :node
attr_reader :href
attr_reader :text
attr_reader :attributes
attr_reader :page
alias :to_s :text
alias :referer :page
def initialize(node, mech, page)
@node = node
@href = node['href']
@text = node.inner_text
@page = page
@mech = mech
@attributes = node
# If there is no text, try to find an image and use it's alt text
if (@text.nil? || @text.length == 0) && node.search('img').length > 0
@text = ''
node.search('img').each do |e|
@text << ( e['alt'] || '')
end
end
end
def uri
@href && URI.parse(URI.encode(@href))
end
# Click on this link
def click
@mech.click self
end
end
end
end
|