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
-
.additional_types ⇒ Object
Dictionary fields can also contain simple hashes.
-
.convert(data, type, document) ⇒ Object
Wraps the given data value in the PDF specific type class if it can be converted.
-
.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.
Class Method Details
.additional_types ⇒ Object
Dictionary fields can also contain simple hashes.
184 185 186 |
# File 'lib/hexapdf/dictionary_fields.rb', line 184 def self.additional_types Hash end |
.convert(data, type, document) ⇒ Object
Wraps the given data value in the PDF specific type class if it can be converted. Otherwise returns nil.
190 191 192 193 194 |
# File 'lib/hexapdf/dictionary_fields.rb', line 190 def self.convert(data, type, document) return if data.kind_of?(type.first) || !(data.kind_of?(Hash) || data.kind_of?(HexaPDF::Dictionary)) document.wrap(data, type: type.first) 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.
178 179 180 181 |
# File 'lib/hexapdf/dictionary_fields.rb', line 178 def self.usable_for?(type) type.kind_of?(Symbol) || (type.respond_to?(:ancestors) && type.ancestors.include?(HexaPDF::Dictionary)) end |