Class: NWN::Resources::Container
- Inherits:
-
Object
- Object
- NWN::Resources::Container
- Defined in:
- lib/nwn/res.rb
Overview
Wraps n ContentObjects; a baseclass for erf/key encapsulation.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
Instance Method Summary collapse
-
#add(o) ⇒ Object
Add a content object giving the ContentObject.
-
#add_file(filename, io = nil) ⇒ Object
Add a content object giving a
filename
and a optionalio
. -
#filenames ⇒ Object
Returns a list of filenames.
-
#get(filename) ⇒ Object
Get the contents of the given filename.
-
#get_content_object(filename) ⇒ Object
Get the ContentObject pointing to the given filename.
- #has?(filename) ⇒ Boolean
-
#initialize ⇒ Container
constructor
A new instance of Container.
Constructor Details
#initialize ⇒ Container
Returns a new instance of Container.
66 67 68 |
# File 'lib/nwn/res.rb', line 66 def initialize @content = [] end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
64 65 66 |
# File 'lib/nwn/res.rb', line 64 def content @content end |
Instance Method Details
#add(o) ⇒ Object
Add a content object giving the ContentObject
85 86 87 |
# File 'lib/nwn/res.rb', line 85 def add o @content << o end |
#add_file(filename, io = nil) ⇒ Object
Add a content object giving a filename
and a optional io
.
80 81 82 |
# File 'lib/nwn/res.rb', line 80 def add_file filename, io = nil @content << ContentObject.new_from(filename, io) end |
#filenames ⇒ Object
Returns a list of filenames
90 91 92 |
# File 'lib/nwn/res.rb', line 90 def filenames @content.map {|x| x.filename } end |
#get(filename) ⇒ Object
Get the contents of the given filename. Raises ENOENT if not mapped.
106 107 108 |
# File 'lib/nwn/res.rb', line 106 def get filename get_content_object(filename.downcase).get end |
#get_content_object(filename) ⇒ Object
Get the ContentObject pointing to the given filename. Raises ENOENT if not mapped.
96 97 98 99 100 101 102 |
# File 'lib/nwn/res.rb', line 96 def get_content_object filename ret = @content.select {|x| filename.downcase == x.filename } raise Errno::ENOENT, "No ContentObject with the given filename found." if ret.size == 0 ret[0] end |
#has?(filename) ⇒ Boolean
70 71 72 73 74 75 76 |
# File 'lib/nwn/res.rb', line 70 def has?(filename) base = File.basename(filename) @content.each {|f| return true if f.filename.downcase == base.downcase } return false end |