Class: RPDF::PDFDictionary
- Defined in:
- lib/rpdf/pdfdictionary.rb
Overview
Dictionary Object
- PDFRef15 p35
Direct Known Subclasses
Instance Attribute Summary collapse
-
#dict ⇒ Object
readonly
Returns the value of attribute dict.
Attributes inherited from PDFObject
#generation_number, #object_number
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize(dict, document = nil) ⇒ PDFDictionary
constructor
A new instance of PDFDictionary.
- #to_s ⇒ Object
-
#update(other) ⇒ Object
Update dictionary with other dictionary.
Methods inherited from PDFObject
#indirect?, #invalidate, #invalidated?, #to_pdf, #to_ref
Constructor Details
#initialize(dict, document = nil) ⇒ PDFDictionary
Returns a new instance of PDFDictionary.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rpdf/pdfdictionary.rb', line 11 def initialize(dict, document=nil) raise Exception.new("PDFDictionary is not a hash") unless dict.kind_of?(Hash) @dict = Hash.new dict.each { |key, value| pdfkey = RPDF.topdfobject(key) pdfvalue = RPDF.topdfobject(value) raise Exception.new("PDFDictionary key must be a name") unless pdfkey.kind_of?(PDFName) @dict[pdfkey] = pdfvalue } super(document) end |
Instance Attribute Details
#dict ⇒ Object (readonly)
Returns the value of attribute dict.
9 10 11 |
# File 'lib/rpdf/pdfdictionary.rb', line 9 def dict @dict end |
Instance Method Details
#[](key) ⇒ Object
23 24 25 26 27 |
# File 'lib/rpdf/pdfdictionary.rb', line 23 def [](key) pdfkey = RPDF.topdfobject(key) raise Exception.new("PDFDictionary key must be a name") unless pdfkey.kind_of?(PDFName) @dict[pdfkey] end |
#[]=(key, value) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/rpdf/pdfdictionary.rb', line 29 def []=(key, value) pdfkey = RPDF.topdfobject(key) pdfvalue = RPDF.topdfobject(value) raise Exception.new("PDFDictionary key must be a name") unless pdfkey.kind_of?(PDFName) @dict[pdfkey] = pdfvalue end |
#to_s ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/rpdf/pdfdictionary.rb', line 41 def to_s bytes = "<< " @dict.each { |key, value| bytes << "#{key.to_s} #{value.to_ref}\n" # to_ref -> reference to indirect object } bytes << ">>\n" end |
#update(other) ⇒ Object
Update dictionary with other dictionary
37 38 39 |
# File 'lib/rpdf/pdfdictionary.rb', line 37 def update(other) @dict.update(other.dict) end |