class HexaPDF::PDFArray
See: PDF2.0 s7.3.6
methods are needed.
#[] method. Therefore not all Array methods are implemented - use the #value directly if other
This is mainly done to provide automatic resolution of indirect object references when using the
Implementation of the PDF array type.
def <<(data)
def <<(data) value << data end
def [](arg1, arg2 = nil)
Note: Hash or Array values will always be returned as-is, i.e. not wrapped with Dictionary or
the hash that describes the Catalog instead of the Catalog object).
subclasses of HexaPDF::Object are returned as is (it makes no sense, for example, to return
* Returns the native Ruby object for values with class HexaPDF::Object. However, all
* References are automatically resolved.
advantages:
This method should be used instead of direct access to a value because it provides some
subarray specified by +range+.
Returns the value at the given index, or a subarray using the given +start+ and +length+, or a
array[range] -> new_array or nil
array[start, length] -> new_array or nil
array[index] -> obj or nil
:call-seq:
def [](arg1, arg2 = nil) data = arg2 ? value[arg1, arg2] : value[arg1] return if data.nil? if arg2 || arg1.kind_of?(Range) index = (arg2 ? arg1 : arg1.begin) data.map! {|item| process_entry(item, index).tap { index += 1 } } else process_entry(data, arg1) end end
def []=(index, data)
subclasses) and the given data has not (including subclasses), the data is stored inside the
If the current value for this index has the class HexaPDF::Object (and only this, no
Stores the data under the given index in the array.
def []=(index, data) if value[index].instance_of?(HexaPDF::Object) && !data.kind_of?(HexaPDF::Object) && !data.kind_of?(HexaPDF::Reference) value[index].value = data else value[index] = data end end
def after_data_change # :nodoc:
Ensures that the value is useful for a PDFArray.
def after_data_change # :nodoc: super data.value ||= [] unless value.kind_of?(Array) raise ArgumentError, "A PDF array object needs an array value, not a #{value.class}" end end
def compact!
Removes all +nil+ elements from the array. Returns +self+ if any elements were removed, +nil+
array.compact! -> array or nil
:call-seq:
def compact! value.compact! && self end
def delete(object)
Deletes all values from the PDFArray that are equal to the given object.
def delete(object) value.delete(object) end
def delete_at(index)
def delete_at(index) value.delete_at(index) end
def each
Calls the given block once for every value of the array.
array.each -> Enumerator
array.each {|value| block} -> array
:call-seq:
def each return to_enum(__method__) unless block_given? value.each_index {|index| yield(self[index]) } self end
def empty?
def empty? value.empty? end
def index(*obj, &block)
Returns the index of the first object such that object is == to +obj+, or, if a block is
array.index -> Enumerator
array.index {|item| block } -> int or nil
array.index(obj) -> int or nil
:call-seq:
def index(*obj, &block) find_index(*obj, &block) end
def insert(index, *objects)
def insert(index, *objects) value.insert(index, *objects) end
def length
def length value.length end
def map!
Maps all elements from the array in-place to the respective return value of the block+ and
array.map! -> Enumerator
array.map! {|item| block } -> array
:call-seq:
def map! return to_enum(__method__) unless block_given? value.map! {|item| yield(process_entry(item)) } self end
def perform_validation(&block) # :nodoc:
def perform_validation(&block) # :nodoc: super each {|element| validate_nested(element, &block) } end
def process_entry(data, index = nil)
def process_entry(data, index = nil) if data.kind_of?(HexaPDF::Reference) data = document.deref(data) value[index] = data if index end if data.instance_of?(HexaPDF::Object) || (data.kind_of?(HexaPDF::Object) && data.value.nil?) data = data.value end data end
def reject!
Deletes all elements from the array for which the block returns +true+ and returns +self+. If
array.reject! -> Enumerator
array.reject! {|item| block } -> array or nil
:call-seq:
def reject! return to_enum(__method__) unless block_given? value.reject! {|item| yield(process_entry(item)) } && self end
def slice!(arg1, arg2 = nil)
Deletes the element(s) given by an index (and optionally a length) or by a range, and returns
array.slice!(range) -> new_array or nil
array.slice!(start, length) -> new_array or nil
array.slice!(index) -> obj or nil
:call-seq:
def slice!(arg1, arg2 = nil) data = value.slice!(arg1, *arg2) if arg2 || arg1.kind_of?(Range) data.map! {|item| process_entry(item) } else process_entry(data) end end
def to_ary
def to_ary each.to_a end
def values_at(*indices)
Returns the values at the given indices.
def values_at(*indices) indices.map! {|index| self[index] } end