class HexaPDF::PDFArray

Parent
Included Modules

Implementation of the PDF array type.

This is mainly done to provide automatic resolution of indirect object references when using the [] method. Therefore not all Array methods are implemented - use the value directly if other methods are needed.

See: PDF2.0 s7.3.6

Public Instance Methods

<<(data)

Append a value to the array.

array[index] → obj or nil
array[start, length] → new_array or nil
array[range] → new_array or nil

Returns the value at the given index, or a subarray using the given start and length, or a subarray specified by range.

This method should be used instead of direct access to a value because it provides some advantages:

  • References are automatically resolved.

  • Returns the native Ruby object for values with class HexaPDF::Object. However, all subclasses of HexaPDF::Object are returned as is (it makes no sense, for example, to return the hash that describes the Catalog instead of the Catalog object).

Note: Hash or Array values will always be returned as-is, i.e. not wrapped with Dictionary or PDFArray.

[]=(index, data)

Stores the data under the given index in the array.

If the current value for this index has the class HexaPDF::Object (and only this, no subclasses) and the given data has not (including subclasses), the data is stored inside the HexaPDF::Object.

compact! → array or nil

Removes all nil elements from the array. Returns self if any elements were removed, nil otherwise.

delete(object)

Deletes all values from the PDFArray that are equal to the given object.

Returns the last deleted item, or nil if no matching item is found.

delete_at(index)

Deletes the value at the given index.

each {|value| block} → array
each → Enumerator

Calls the given block once for every value of the array.

Note that the yielded value is already preprocessed like in [].

empty?()

Returns true if the array has no elements.

index(obj) → int or nil
index {|item| block } → int or nil
index → Enumerator

Returns the index of the first object such that object is == to obj, or, if a block is given, the index of the first object for which the block returns true.

insert(index, *objects)

Insert one or more values into the array at the given index.

length()

Returns the number of elements in the array.

Also aliased as: size
map! {|item| block } → array
map! → Enumerator

Maps all elements from the array in-place to the respective return value of the block+ and returns self.

reject! {|item| block } → array or nil
reject! → Enumerator

Deletes all elements from the array for which the block returns true and returns self. If no changes were done, returns nil.

size()
Alias for: length
slice!(index) → obj or nil
slice!(start, length) → new_array or nil
slice!(range) → new_array or nil

Deletes the element(s) given by an index (and optionally a length) or by a range, and returns them or nil if the index is out of range.

to_ary()

Returns an array containing the preprocessed values (like in []).

values_at(*indices)

Returns the values at the given indices.

See [] for details