Class: PDF::Reader::ObjectCache
- Inherits:
-
Object
- Object
- PDF::Reader::ObjectCache
- Defined in:
- lib/pdf/reader/object_cache.rb
Overview
A Hash-like object for caching commonly used objects from a PDF file.
This is an internal class used by PDF::Reader::ObjectHash
Constant Summary collapse
- CACHEABLE_TYPES =
These object types use little memory and are accessed a heap of times as part of random page access, so we’ll cache the unmarshalled objects and avoid lots of repetitive (and expensive) tokenising
[:Catalog, :Page, :Pages]
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #each(&block) ⇒ Object (also: #each_pair)
- #each_key(&block) ⇒ Object
- #each_value(&block) ⇒ Object
- #empty? ⇒ Boolean
- #fetch(key, local_default = nil) ⇒ Object
- #has_key?(key) ⇒ Boolean (also: #include?, #key?, #member?)
- #has_value?(value) ⇒ Boolean
-
#initialize ⇒ ObjectCache
constructor
A new instance of ObjectCache.
- #keys ⇒ Object
- #size ⇒ Object (also: #length)
- #to_s ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize ⇒ ObjectCache
Returns a new instance of ObjectCache.
16 17 18 |
# File 'lib/pdf/reader/object_cache.rb', line 16 def initialize @objects = {} end |
Instance Method Details
#[](key) ⇒ Object
20 21 22 |
# File 'lib/pdf/reader/object_cache.rb', line 20 def [](key) @objects[key] end |
#[]=(key, value) ⇒ Object
24 25 26 |
# File 'lib/pdf/reader/object_cache.rb', line 24 def []=(key, value) @objects[key] = value if cacheable?(value) end |
#each(&block) ⇒ Object Also known as: each_pair
32 33 34 |
# File 'lib/pdf/reader/object_cache.rb', line 32 def each(&block) @objects.each(&block) end |
#each_key(&block) ⇒ Object
37 38 39 |
# File 'lib/pdf/reader/object_cache.rb', line 37 def each_key(&block) @objects.each_key(&block) end |
#each_value(&block) ⇒ Object
41 42 43 |
# File 'lib/pdf/reader/object_cache.rb', line 41 def each_value(&block) @objects.each_value(&block) end |
#empty? ⇒ Boolean
50 51 52 |
# File 'lib/pdf/reader/object_cache.rb', line 50 def empty? @objects.empty? end |
#fetch(key, local_default = nil) ⇒ Object
28 29 30 |
# File 'lib/pdf/reader/object_cache.rb', line 28 def fetch(key, local_default = nil) @objects.fetch(key, local_default) end |
#has_key?(key) ⇒ Boolean Also known as: include?, key?, member?
54 55 56 |
# File 'lib/pdf/reader/object_cache.rb', line 54 def has_key?(key) @objects.has_key?(key) end |
#has_value?(value) ⇒ Boolean
61 62 63 |
# File 'lib/pdf/reader/object_cache.rb', line 61 def has_value?(value) @objects.has_value?(value) end |
#keys ⇒ Object
69 70 71 |
# File 'lib/pdf/reader/object_cache.rb', line 69 def keys @objects.keys end |
#size ⇒ Object Also known as: length
45 46 47 |
# File 'lib/pdf/reader/object_cache.rb', line 45 def size @objects.size end |
#to_s ⇒ Object
65 66 67 |
# File 'lib/pdf/reader/object_cache.rb', line 65 def to_s "<PDF::Reader::ObjectCache size: #{self.size}>" end |
#values ⇒ Object
73 74 75 |
# File 'lib/pdf/reader/object_cache.rb', line 73 def values @objects.values end |