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.



148
149
150
151
# File 'lib/nwn/res.rb', line 148

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

Instance Method Details

#add_container(c) ⇒ Object



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

def add_container c
  @path << c
end

#contentObject

Get a list of filenames contained inside.



174
175
176
177
178
# File 'lib/nwn/res.rb', line 174

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.



169
170
171
# File 'lib/nwn/res.rb', line 169

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)


159
160
161
162
163
164
165
# File 'lib/nwn/res.rb', line 159

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