Class: PDF::Reader::Error

Inherits:
Object
  • Object
show all
Defined in:
lib/pdf/reader/error.rb

Overview

An internal PDF::Reader class that helps to verify various parts of the PDF file are valid

Class Method Summary collapse

Class Method Details

.assert_equal(lvalue, rvalue) ⇒ Object

: (untyped, untyped) -> untyped

Raises:



49
50
51
# File 'lib/pdf/reader/error.rb', line 49

def self.assert_equal(lvalue, rvalue)
  raise MalformedPDFError, "PDF malformed, expected '#{rvalue}' but found '#{lvalue}' instead" if lvalue != rvalue
end

.str_assert(lvalue, rvalue, chars = nil) ⇒ Object

: (untyped, untyped, ?untyped) -> untyped

Raises:



35
36
37
38
39
# File 'lib/pdf/reader/error.rb', line 35

def self.str_assert(lvalue, rvalue, chars=nil)
  raise MalformedPDFError, "PDF malformed, expected string but found #{lvalue.class} instead" if chars and !lvalue.kind_of?(String)
  lvalue = lvalue[0,chars] if chars
  raise MalformedPDFError, "PDF malformed, expected '#{rvalue}' but found '#{lvalue}' instead"  if lvalue != rvalue
end

.str_assert_not(lvalue, rvalue, chars = nil) ⇒ Object

: (untyped, untyped, ?untyped) -> untyped

Raises:



42
43
44
45
46
# File 'lib/pdf/reader/error.rb', line 42

def self.str_assert_not(lvalue, rvalue, chars=nil)
  raise MalformedPDFError, "PDF malformed, expected string but found #{lvalue.class} instead" if chars and !lvalue.kind_of?(String)
  lvalue = lvalue[0,chars] if chars
  raise MalformedPDFError, "PDF malformed, expected '#{rvalue}' but found '#{lvalue}' instead"  if lvalue == rvalue
end

.validate_not_nil(object, name) ⇒ Object

: (Object, String) -> void

Raises:

  • (ArgumentError)


64
65
66
# File 'lib/pdf/reader/error.rb', line 64

def self.validate_not_nil(object, name)
  raise ArgumentError, "#{object} must not be nil" if object.nil?
end

.validate_type(object, name, klass) ⇒ Object

: (Object, String, Module) -> void

Raises:

  • (ArgumentError)


54
55
56
# File 'lib/pdf/reader/error.rb', line 54

def self.validate_type(object, name, klass)
  raise ArgumentError, "#{name} (#{object}) must be a #{klass}" unless object.is_a?(klass)
end

.validate_type_as_malformed(object, name, klass) ⇒ Object

: (Object, String, Module) -> void

Raises:



59
60
61
# File 'lib/pdf/reader/error.rb', line 59

def self.validate_type_as_malformed(object, name, klass)
  raise MalformedPDFError, "#{name} (#{object}) must be a #{klass}" unless object.is_a?(klass)
end