Class Mechanize::Page::Image
In: lib/mechanize/page/image.rb
Parent: Object

An image element on an HTML page

Methods

alt   caption   dom_class   dom_id   extname   fetch   height   mime_type   new   src   text   title   to_s   url   width  

External Aliases

pretty_inspect -> inspect

Attributes

mech  [RW] 
node  [R] 
page  [RW] 

Public Class methods

Creates a new Mechanize::Page::Image from an image node and source page.

Public Instance methods

The alt attribute of the image

The caption of the image. In order of preference, the title, alt, or empty string "".

The class attribute of the image

The id attribute of the image

The suffix of the url. 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 url has no suffix:

  p image.url     # => "http://example/sampleimage"
  p image.extname # => ""

Downloads the image.

  agent.page.image_with(:src => /logo/).fetch.save

The referer is:

page("parent") :all images on http html, relative src images on https html
(no referer) :absolute src images on https html
user specified :img.fetch(nil, my_referer_uri_or_page)

The height attribute of the image

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

The src attribute of the image

text()

Alias for caption

The title attribute of the image

The URL string of this image

URI for this image

The width attribute of the image

[Validate]