Parent

Included Modules

Class/Module Index [+]

Quicksearch

Origami::Dictionary

Class representing a Dictionary Object. Dictionaries are containers associating a Name to an embedded Object.

Attributes

names_cache[R]
strings_cache[R]
xref_cache[R]

Public Class Methods

hint_type(name) click to toggle source
# File lib/origami/dictionary.rb, line 267
def self.hint_type(name); nil end
native_type() click to toggle source
# File lib/origami/dictionary.rb, line 243
def self.native_type; Dictionary end
new(hash = {}) click to toggle source

Creates a new Dictionary.

hash

The hash representing the new Dictionary.

# File lib/origami/dictionary.rb, line 48
def initialize(hash = {})
  raise TypeError, "Expected type Hash, received #{hash.class}." unless hash.is_a?(Hash)
  super()
  
  @strings_cache = []
  @names_cache = []
  @xref_cache = {}

  hash.each_pair do |k,v|
    @names_cache.push(k.to_o)
    case val = v.to_o
      when String then @strings_cache.push(val)
      when Name then @names_cache.push(val)
      when Reference then
        (@xref_cache[val] ||= []).push(self)
      when Dictionary,Array then 
        @strings_cache.concat(val.strings_cache)
        @names_cache.concat(val.names_cache)
        @xref_cache.update(val.xref_cache) do |ref, cache1, cache2|
          cache1.concat(cache2)  
        end

        val.strings_cache.clear
        val.names_cache.clear
        val.xref_cache.clear
    end

    self[k.to_o] = val unless k.nil?
  end
end

Public Instance Methods

[](key) click to toggle source
# File lib/origami/dictionary.rb, line 184
def [](key)
  super(key.to_o)
end
[]=(key,val) click to toggle source
# File lib/origami/dictionary.rb, line 165
def []=(key,val)
  unless key.is_a?(Symbol) or key.is_a?(Name)
    fail "Expecting a Name for a Dictionary entry, found #{key.class} instead."
  end
  
  key = key.to_o
  if not val.nil?
    val = val.to_o
    super(key,val)
    
    key.parent = self
    val.parent = self unless val.is_indirect? or val.parent.equal?(self)

    val
  else
    delete(key)
  end
end
cast_to(type) click to toggle source
# File lib/origami/dictionary.rb, line 196
def cast_to(type)
  super(type)

  cast = type.new(self)
  cast.parent = self.parent
  cast.no, cast.generation = self.no, self.generation
  if self.is_indirect?
    cast.set_indirect(true) 
    cast.set_pdf(self.pdf) 
    cast.file_offset = self.file_offset # cast can replace self
  end

  cast.xref_cache.update(self.xref_cache)
  cast.names_cache.concat(self.names_cache)
  cast.strings_cache.concat(self.strings_cache)

  cast
end
copy() click to toggle source
# File lib/origami/dictionary.rb, line 230
def copy
  copy = self.class.new
  self.each_pair do |k,v|
    copy[k] = v.copy 
  end 

  copy.parent = @parent
  copy.no, copy.generation = @no, @generation
  copy.set_indirect(true) if is_indirect?
  copy.set_pdf(@pdf) if is_indirect?
  copy
end
delete(key) click to toggle source
# File lib/origami/dictionary.rb, line 192
def delete(key)
  super(key.to_o)
end
has_key?(key) click to toggle source
# File lib/origami/dictionary.rb, line 188
def has_key?(key)
  super(key.to_o)
end
map!(&b) click to toggle source
# File lib/origami/dictionary.rb, line 155
def map!(&b)
  self.each_pair do |k,v|
    self[k] = b.call(v)
  end
end
merge(dict) click to toggle source
# File lib/origami/dictionary.rb, line 161
def merge(dict)
  Dictionary.new(super(dict))
end
to_obfuscated_str() click to toggle source
# File lib/origami/obfuscation.rb, line 117
def to_obfuscated_str
  content = TOKENS.first + Obfuscator.junk_spaces
  self.each_pair { |key, value|
    content << Obfuscator.junk_spaces + 
      key.to_obfuscated_str + Obfuscator.junk_spaces + 
      value.to_obfuscated_str + Obfuscator.junk_spaces
  }

  content << TOKENS.last
  super(content)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.