Skip to content

Commit

Permalink
Sort and cleanup Link#text
Browse files Browse the repository at this point in the history
  • Loading branch information
drbrain committed Jun 24, 2011
1 parent 9787dba commit 1777f7a
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions lib/mechanize/page/link.rb
Expand Up @@ -16,12 +16,12 @@ class Mechanize::Page::Link
alias :referer :page

def initialize(node, mech, page)
@node = node
@href = node['href']
@text = nil
@page = page
@mech = mech
@node = node
@attributes = node
@href = node['href']
@mech = mech
@page = page
@text = nil
end

# Click on this link
Expand All @@ -30,7 +30,8 @@ def click
end

# This method is a shorthand to get link's DOM id.
# Common usage: page.link_with(:dom_id => "links_exact_id")
# Common usage:
# page.link_with(:dom_id => "links_exact_id")
def dom_id
node['id']
end
Expand All @@ -41,23 +42,21 @@ def rel
end

# Test if the rel attribute includes +kind+.
def rel?(kind)
rel.include?(kind)
def rel? kind
rel.include? kind
end

# The text content of this link
def text
return @text if @text

@text = node.inner_text
@text = @node.inner_text

# If there is no text, try to find an image and use it's alt text
if (@text.nil? or @text.empty?) and not node.search('img').empty? then
@text = ''

@node.search('img').each do |e|
@text << ( e['alt'] || '')
end
if (@text.nil? or @text.empty?) and imgs = @node.search('img') then
@text = imgs.map do |e|
e['alt']
end.join
end

@text
Expand Down

0 comments on commit 1777f7a

Please sign in to comment.