Method: RTF::ImageNode#initialize

Defined in:
lib/rtf/node.rb

#initialize(parent, source, id) ⇒ ImageNode

This is the constructor for the ImageNode class.

Parameters

parent

A reference to the node that owns the new image node.

source

A reference to the image source. This must be a String or a File.

id

The unique identifier for the image node.

Exceptions

RTFError

Generated whenever the image specified is not recognised as a supported image type, something other than a String or File or IO is passed as the source parameter or if the specified source does not exist or cannot be accessed.



1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
# File 'lib/rtf/node.rb', line 1284

def initialize(parent, source, id)
   super(parent)
   @source = nil
   @id     = id
   @read   = []
   @type   = nil
   @x_scaling = @y_scaling = nil
   @top_crop = @right_crop = @bottom_crop = @left_crop = nil
   @width = @height = nil

   # Check what we were given.
   src = source
   src.binmode if src.instance_of?(File)
   src = File.new(source, 'rb') if source.instance_of?(String)
   if src.instance_of?(File)
      # Check the files existence and accessibility.
      if !File.exist?(src.path)
         RTFError.fire("Unable to find the #{File.basename(source)} file.")
      end
      if !File.readable?(src.path)
         RTFError.fire("Access to the #{File.basename(source)} file denied.")
      end
      @source = src
   else
      RTFError.fire("Unrecognised source specified for ImageNode.")
   end

   @type = get_file_type(src)
   if @type == nil
      RTFError.fire("The #{File.basename(source)} file contains an "\
                    "unknown or unsupported image type.")
   end

   @width, @height = get_dimensions
end