An image element on an HTML page
Creates a new Mechanize::Page::Image from an image node and source page.
# File lib/mechanize/page/image.rb, line 14 14: def initialize node, page 15: @node = node 16: @page = page 17: @mech = page.mech 18: end
The alt attribute of the image
# File lib/mechanize/page/image.rb, line 23 23: def alt 24: node['alt'] 25: end
The caption of the image. In order of preference, the #, #, or empty string “”.
# File lib/mechanize/page/image.rb, line 31 31: def caption 32: title || alt || '' 33: end
The class attribute of the image
# File lib/mechanize/page/image.rb, line 40 40: def dom_class 41: node['class'] 42: end
The id attribute of the image
# File lib/mechanize/page/image.rb, line 47 47: def dom_id 48: node['id'] 49: end
The suffix of the #. The dot is a part of suffix, not a delimiter.
p image.url # => "http://example/test.jpg" p image.extname # => ".jpg"
Returns an empty string if # has no suffix:
p image.url # => "http://example/sampleimage" p image.extname # => ""
# File lib/mechanize/page/image.rb, line 62 62: def extname 63: return nil unless src 64: 65: File.extname url.path 66: end
Downloads the image.
agent.page.image_with(:src => /logo/).fetch.save
The referer is:
#(“parent”) | all images on http html, relative # images on https html |
(no referer) | absolute # images on https html |
user specified | img.fetch(nil, my_referer_uri_or_page) |
# File lib/mechanize/page/image.rb, line 82 82: def fetch parameters = [], referer = nil, headers = {} 83: mech.get src, parameters, referer || image_referer, headers 84: end
The height attribute of the image
# File lib/mechanize/page/image.rb, line 89 89: def height 90: node['height'] 91: end
MIME type guessed from the image url suffix
p image.extname # => ".jpg" p image.mime_type # => "image/jpeg" page.images_with(:mime_type => /gif|jpeg|png/).each do ...
Returns nil if url has no (well-known) suffix:
p image.url # => "http://example/sampleimage" p image.mime_type # => nil
# File lib/mechanize/page/image.rb, line 117 117: def mime_type 118: suffix_without_dot = extname ? extname.sub(/\A\./){''}.downcase : nil 119: 120: Mechanize::Util::DefaultMimeTypes[suffix_without_dot] 121: end
The src attribute of the image
# File lib/mechanize/page/image.rb, line 139 139: def src 140: node['src'] 141: end
The title attribute of the image
# File lib/mechanize/page/image.rb, line 146 146: def title 147: node['title'] 148: end
The URL string of this image
# File lib/mechanize/page/image.rb, line 153 153: def to_s 154: url.to_s 155: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.