Class: Celerity::Image

Included Modules

Celerity::ClickableElement

Constants

ATTRIBUTES
BASE_ATTRIBUTES | [:src, :alt, :longdesc, :name, :height, :width, :usemap, :ismap, :align, :border, :hspace, :vspace]
DEFAULT_HOW
:src
TAGS
[ Identifier.new('img') ]

Constructor Summary

This class inherits a constructor from Celerity::Element.

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Celerity::Element

public String method_missing(meth, *args, &blk)

Dynamically get element attributes.

Meta Tags

Parameters:

Returns:

[String]

The resulting attribute.

Raises:

[NoMethodError]

if the element doesn’t support this attribute.

See Also:

ATTRIBUTES constant for a list of valid methods for a given element.
[View source]


235
236
237
238
239
240
241
242
243
244
245
# File 'lib/celerity/element.rb', line 235

def method_missing(meth, *args, &blk)
  assert_exists

  meth = selector_to_attribute(meth)

  if self.class::ATTRIBUTES.include?(meth) || (self.class == Element && @object.hasAttribute(meth.to_s))
    return @object.getAttribute(meth.to_s)
  end
  Log.warn "Element\#method_missing calling super with #{meth.inspect}"
  super
end

Public Visibility

Public Instance Method Summary

#file_created_date #fileCreatedDate

returns the file created date of the image.

#file_size #fileSize

returns the file size of the image in bytes.

#height

returns the height in pixels of the image, as a string.

#loaded? #has_loaded? #hasLoaded?

returns true if the image is loaded.

#save(filename)

Saves the image to the given file.

#width

returns the width in pixels of the image, as a string.

Public Instance Method Details

file_created_date

public file_created_date

Also known as: fileCreatedDate

returns the file created date of the image

[View source]


15
16
17
18
19
# File 'lib/celerity/elements/image.rb', line 15

def file_created_date
  assert_exists
  web_response = @object.getWebResponse(true)
  Time.parse(web_response.getResponseHeaderValue("Last-Modified").to_s)
end

file_size

public file_size

Also known as: fileSize

returns the file size of the image in bytes

[View source]


25
26
27
28
29
# File 'lib/celerity/elements/image.rb', line 25

def file_size
  assert_exists
  web_response = @object.getWebResponse(true)
  web_response.getContentAsBytes.length
end

height

public height

returns the height in pixels of the image, as a string

[View source]


44
45
46
47
# File 'lib/celerity/elements/image.rb', line 44

def height
  assert_exists
  @object.getHeight
end

loaded?

public loaded?

Also known as: has_loaded? hasLoaded?

returns true if the image is loaded

[View source]


53
54
55
56
57
58
59
60
61
# File 'lib/celerity/elements/image.rb', line 53

def loaded?
  assert_exists
  begin
    @object.getImageReader
    true
  rescue
    false
  end
end

save

public save(filename)

Saves the image to the given file

[View source]


67
68
69
70
71
72
73
# File 'lib/celerity/elements/image.rb', line 67

def save(filename)
  assert_exists
  image_reader = @object.getImageReader
  file = java.io.File.new(filename)
  buffered_image = image_reader.read(0);
  javax.imageio.ImageIO.write(buffered_image, image_reader.getFormatName(), file);
end

width

public width

returns the width in pixels of the image, as a string

[View source]


35
36
37
38
# File 'lib/celerity/elements/image.rb', line 35

def width
  assert_exists
  @object.getWidth
end