Module: HexaPDF::DictionaryFields::DictionaryConverter

Defined in:
lib/hexapdf/dictionary_fields.rb

Overview

Converter module for fields of type Dictionary and its subclasses. The first class in the type array of the field is used for the conversion.

Class Method Summary collapse

Class Method Details

.additional_typesObject

Dictionary fields can also contain simple hashes.



214
215
216
# File 'lib/hexapdf/dictionary_fields.rb', line 214

def self.additional_types
  Hash
end

.convert(data, type, document) ⇒ Object

Wraps the given data value in the PDF specific type class.



226
227
228
# File 'lib/hexapdf/dictionary_fields.rb', line 226

def self.convert(data, type, document)
  document.wrap(data, type: type.first)
end

.convert?(data, type) ⇒ Boolean

Returns true if the given data value can be converted to the Dictionary subclass specified by type (see Field#type).

Returns:



220
221
222
223
# File 'lib/hexapdf/dictionary_fields.rb', line 220

def self.convert?(data, type)
  !data.kind_of?(type.first) && (data.kind_of?(Hash) ||
    data.kind_of?(HexaPDF::Dictionary))
end

.usable_for?(type) ⇒ Boolean

This converter is used when either a Symbol is provided as type (for lazy loading) or when the type is a class derived from the Dictionary class.

Returns:



208
209
210
211
# File 'lib/hexapdf/dictionary_fields.rb', line 208

def self.usable_for?(type)
  type.kind_of?(Symbol) ||
    (type.respond_to?(:ancestors) && type.ancestors.include?(HexaPDF::Dictionary))
end