Module: NWN::Gff::Handler
- Defined in:
- lib/nwn/gff.rb
Overview
A namesoace for all Gff file format handlers.
Defined Under Namespace
Modules: Gff, JSON, Kivinen, Marshal, Pretty, YAML Classes: XML
Class Method Summary collapse
-
.register(name, fileFormatRegexp, klass, reads = true, writes = true) ⇒ Object
Registers a new format handler that can deal with file formats for nwn-lib gff handling.
Class Method Details
.register(name, fileFormatRegexp, klass, reads = true, writes = true) ⇒ Object
Registers a new format handler that can deal with file formats for nwn-lib gff handling.
name
-
The name of this format as a symbol. Must be unique.
fileFormatRegexp
-
A regular expression matching file extensions for auto-detection.
klass
-
A object that responds to load(io) and dump(gff,io). load(io) reads from io and always returns a NWN::Gff::Struct describing a root struct, dump(gff, io) dumps the gff root struct in the handlers format to io and returns the number of bytes written.
reads
-
Boolean, indicates if this handler can read it’s format and return gff data.
writes
-
Boolean, indicates if this handler can emit gff data in it’s format.
32 33 34 35 36 37 38 |
# File 'lib/nwn/gff.rb', line 32 def self.register name, fileFormatRegexp, klass, reads = true, writes = true raise ArgumentError, "Handler for #{name.inspect} already registered." if NWN::Gff::InputFormats[name.to_sym] || NWN::Gff::OutputFormats[name.to_sym] NWN::Gff::InputFormats[name.to_sym] = klass if reads NWN::Gff::OutputFormats[name.to_sym] = klass if writes NWN::Gff::FileFormatGuesses[name.to_sym] = fileFormatRegexp end |