class HexaPDF::DictionaryFields::Field
from its string representation to a Time object.
automatically, like checking for the correct minimum PDF version to use or converting a date
By incorporating this field information into HexaPDF it is possible to do many things
comes directly from the PDF specification.
A field contains information about one field of a structured PDF object and this information
def self.converter_for(type)
the back. So if two converters could potentially be used for the same type, the one that
The converter list from #converters is checked for a suitable converter from the front to
Returns the converter for the given +type+ specification.
def self.converter_for(type) @converters.find {|converter| converter.usable_for?(type) } end
def self.converters
Returns the list of available converter objects.
def self.converters @converters ||= [] end
def convert(data, document)
def convert(data, document) @converters.each do |converter| result = converter.convert(data, type, document) return result unless result.nil? end nil end
def default
def default @default.dup end
def default?
def default? !@default.nil? end
def initialize(type, required: false, default: nil, indirect: nil, allowed_values: nil,
Depending on the +type+ entry an appropriate field converter object is chosen from the
Create a new Field object. See Dictionary::define_field for information on the arguments.
def initialize(type, required: false, default: nil, indirect: nil, allowed_values: nil, version: nil) @type = [type].flatten @type_mapped = false @required, @default, @indirect, @version = required, default, indirect, version @allowed_values = allowed_values && [allowed_values].flatten @converters = @type.map {|t| self.class.converter_for(t) }.compact end
def required?
def required? @required end
def type
def type return @type if @type_mapped @type.concat(@converters.flat_map(&:additional_types).compact) @type.map! do |type| if type.kind_of?(Symbol) HexaPDF::GlobalConfiguration.constantize('object.type_map', type) else type end end @type.uniq! @type_mapped = true @type end
def valid_object?(obj)
def valid_object?(obj) type.any? {|t| obj.kind_of?(t) } || (obj.kind_of?(HexaPDF::Object) && type.any? {|t| obj.value.kind_of?(t) }) end