Class: PDF::Reader::Error
- Inherits:
-
Object
- Object
- PDF::Reader::Error
- 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
- .assert_equal(lvalue, rvalue) ⇒ Object
-
.str_assert(lvalue, rvalue, chars = nil) ⇒ Object
:nodoc:.
- .str_assert_not(lvalue, rvalue, chars = nil) ⇒ Object
- .validate_not_nil(object, name) ⇒ Object
- .validate_type(object, name, klass) ⇒ Object
- .validate_type_as_malformed(object, name, klass) ⇒ Object
Class Method Details
.assert_equal(lvalue, rvalue) ⇒ Object
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:
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
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
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
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
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 |