Method: HexaPDF::Object#validate
- Defined in:
- lib/hexapdf/object.rb
#validate(auto_correct: true) ⇒ Object
:call-seq:
obj.validate(auto_correct: true) -> true or false
obj.validate(auto_correct: true) {|msg, correctable, obj| block } -> true or false
Validates the object, optionally corrects problems when the option auto_correct is set and returns true if the object is deemed valid and false otherwise.
If a block is given, it is called on validation problems with a problem description and whether the problem is automatically correctable. The third argument to the block is usually this object but may be another object if during auto-correction a new object was created and validated.
The validation routine itself has to be implemented in the #perform_validation method - see its documentation for more information.
Note: Even if the return value is true there may be problems since HexaPDF doesn’t currently implement the full PDF spec. However, if the return value is false, there is certainly a problem!
298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'lib/hexapdf/object.rb', line 298 def validate(auto_correct: true) result = true perform_validation do |msg, correctable, object| yield(msg, correctable, object || self) if block_given? result = false unless correctable return false unless auto_correct end result rescue HexaPDF::Error raise rescue StandardError => e yield("Unexpected error encountered: #{e.}", false, self) if block_given? false end |