Class: NWN::Resources::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/nwn/res.rb

Overview

The resource manager, providing ordered access to Container objects.

Instance Method Summary collapse

Constructor Details

#initializeManager

Returns a new instance of Manager.



125
126
127
128
# File 'lib/nwn/res.rb', line 125

def initialize
  @path = []
  @_content_cache = nil
end

Instance Method Details

#add_container(c) ⇒ Object



130
131
132
# File 'lib/nwn/res.rb', line 130

def add_container c
  @path << c
end

#contentObject

Get a list of filenames contained inside.



151
152
153
154
155
# File 'lib/nwn/res.rb', line 151

def content
  @_content_cache ||= @path.inject([]) {|a, x|
    a |= x.filenames
  }
end

#get(filename) ⇒ Object

Get the contents of the given filename. Raises ENOENT if not mapped.



146
147
148
# File 'lib/nwn/res.rb', line 146

def get filename
  get_content_object(filename).get
end

#get_content_object(filename) ⇒ Object

Get the ContentObject pointing to the given filename. Raises ENOENT if not mapped.

Raises:

  • (Errno::ENOENT)


136
137
138
139
140
141
142
# File 'lib/nwn/res.rb', line 136

def get_content_object filename
  @path.reverse.each {|con|
    con.has?(filename) or next
    return con.get_content_object(filename)
  }
  raise Errno::ENOENT, "No ContentObject with the given filename found."
end