module HexaPDF::DictionaryFields::DictionaryConverter
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.
Public Class Methods
additional_types()
click to toggle source
Dictionary
fields can also contain simple hashes.
# File lib/hexapdf/dictionary_fields.rb, line 185 def self.additional_types Hash end
convert(data, type, document)
click to toggle source
Wraps the given data value in the PDF specific type class if it can be converted. Otherwise returns nil
.
# File lib/hexapdf/dictionary_fields.rb, line 191 def self.convert(data, type, document) return if data.kind_of?(type.first) || !(data.kind_of?(Hash) || data.kind_of?(HexaPDF::Dictionary)) || (type.first <= HexaPDF::Stream && (data.kind_of?(Hash) || data.data.stream.nil?)) document.wrap(data, type: type.first) end
usable_for?(type)
click to toggle source
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.
# File lib/hexapdf/dictionary_fields.rb, line 179 def self.usable_for?(type) type.kind_of?(Symbol) || (type.respond_to?(:ancestors) && type.ancestors.include?(HexaPDF::Dictionary)) end