Class: NWN::Resources::Manager
- Inherits:
-
Object
- Object
- NWN::Resources::Manager
- Defined in:
- lib/nwn/res.rb
Overview
The resource manager, providing ordered access to Container objects.
Instance Method Summary collapse
- #add_container(c) ⇒ Object
-
#content ⇒ Object
Get a list of filenames contained inside.
-
#get(filename) ⇒ Object
Get the contents of the given filename.
-
#get_content_object(filename) ⇒ Object
Get the ContentObject pointing to the given filename.
-
#initialize ⇒ Manager
constructor
A new instance of Manager.
Constructor Details
#initialize ⇒ Manager
Returns a new instance of Manager.
129 130 131 132 |
# File 'lib/nwn/res.rb', line 129 def initialize @path = [] @_content_cache = nil end |
Instance Method Details
#add_container(c) ⇒ Object
134 135 136 |
# File 'lib/nwn/res.rb', line 134 def add_container c @path << c end |
#content ⇒ Object
Get a list of filenames contained inside.
155 156 157 158 159 |
# File 'lib/nwn/res.rb', line 155 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.
150 151 152 |
# File 'lib/nwn/res.rb', line 150 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.
140 141 142 143 144 145 146 |
# File 'lib/nwn/res.rb', line 140 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 #{filename.inspect} found." end |