Class NWN::Resources::Container

  1. lib/nwn/res.rb
Parent: Object

Wraps n ContentObjects; a baseclass for erf/key encapsulation.

Methods

public class

  1. new

public instance

  1. add
  2. add_file
  3. filenames
  4. get
  5. get_content_object
  6. has?

Attributes

content [R] An array of all ContentObjects indexed by this Container.

Public class methods

new ()
[show source]
# File lib/nwn/res.rb, line 68
      def initialize
        @content = []
      end

Public instance methods

add (o)

Add a content object giving the ContentObject

[show source]
# File lib/nwn/res.rb, line 85
      def add o
        @content << o
      end
add_file (filename, io = nil)

Add a content object giving a filename and a optional io.

[show source]
# File lib/nwn/res.rb, line 80
      def add_file filename, io = nil
        @content << ContentObject.new_from(filename, io)
      end
filenames ()

Returns a list of filenames, all lowercase.

[show source]
# File lib/nwn/res.rb, line 90
      def filenames
        @content.map {|x| x.filename.downcase }
      end
get (filename)

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

[show source]
# File lib/nwn/res.rb, line 107
      def get filename
        get_content_object(filename).get
      end
get_content_object (filename)

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

[show source]
# File lib/nwn/res.rb, line 96
      def get_content_object filename
        filename = filename.downcase
        ret = @content.select {|x| filename == x.filename }
        raise Errno::ENOENT,
          "No ContentObject with the given filename #{filename.inspect} found." if
            ret.size == 0
        ret[0]
      end
has? (filename)

Returns true if the given filename is contained herein. Case-insensitive.

[show source]
# File lib/nwn/res.rb, line 74
      def has?(filename)
        filenames.index(filename.downcase) != nil
      end