Class: Chunker::DataParser
- Inherits:
-
Object
- Object
- Chunker::DataParser
- Defined in:
- lib/chunker.rb
Overview
Parser class for __END__ data blocks. Find each __TOKEN__ within the __END__, and put each into a DATA_TOKEN constant within the namespace that included us.
Constant Summary collapse
- END_TOKEN =
The mark for a DATA block.
/^__END__\r?\n/
- CHUNK_TOKEN =
The mark for a ‘sub’ block.
/^__([A-Z\_0-9]+)__\r?\n/
Instance Method Summary collapse
-
#initialize(klass, io) ⇒ DataParser
constructor
Constructor: Given a
klass
and anio
to the class file, extract the data blocks and install constants.
Constructor Details
#initialize(klass, io) ⇒ DataParser
Constructor: Given a klass
and an io
to the class file, extract the data blocks and install constants.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/chunker.rb', line 54 def initialize( klass, io ) io.open if io.closed? end_string = io.read.split( END_TOKEN, 2 ).last @klass = klass @scanner = StringScanner.new( end_string ) io.close if @scanner.check_until( CHUNK_TOKEN ) # put each chunk into its own constant self.extract_blocks else # no sub blocks, put the whole mess into DATA_END @klass.const_set( :DATA_END, StringIO.new( end_string ) ) end end |