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

Raises:



46
47
48
# File 'lib/pdf/reader/error.rb', line 46

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

:nodoc:

Raises:



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

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

Raises:



40
41
42
43
44
# File 'lib/pdf/reader/error.rb', line 40

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

Raises:

  • (ArgumentError)


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

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

.validate_type(object, name, klass) ⇒ Object

Raises:

  • (ArgumentError)


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

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

Raises:



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

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