Module: HexaPDF::DictionaryFields::PDFByteStringConverter

Defined in:
lib/hexapdf/dictionary_fields.rb

Overview

Converter module for binary string fields to automatically convert a string into binary encoding.

Class Method Summary collapse

Class Method Details

.additional_typesObject

:nodoc:



270
271
272
# File 'lib/hexapdf/dictionary_fields.rb', line 270

def self.additional_types
  String
end

.convert(str, _type, _document) ⇒ Object

Converts the string into UTF-8 encoding, assuming it is currently a binary string.



280
281
282
# File 'lib/hexapdf/dictionary_fields.rb', line 280

def self.convert(str, _type, _document)
  str.force_encoding(Encoding::BINARY)
end

.convert?(data, _type) ⇒ Boolean

Returns true if the given data should be converted to a UTF-8 encoded string.

Returns:



275
276
277
# File 'lib/hexapdf/dictionary_fields.rb', line 275

def self.convert?(data, _type)
  data.kind_of?(String) && data.encoding != Encoding::BINARY
end

.usable_for?(type) ⇒ Boolean

This converter is usable if the type is PDFByteString.

Returns:



265
266
267
# File 'lib/hexapdf/dictionary_fields.rb', line 265

def self.usable_for?(type)
  type == PDFByteString
end