Class: RTFReader
- Inherits:
-
Object
- Object
- RTFReader
- Defined in:
- lib/oddb/redist/rtf_tools/reader.rb
Overview
Class : rtf_tools/reader
Version : 1.000 Dated : 25th January 2003 Author : Peter Hickman <[email protected]>
Description
Take a string of RTF as input and return it token by token.
Direct Known Subclasses
Constant Summary collapse
- TOKEN_CONTROL =
'control'
- TOKEN_EOF =
'eof'
- TOKEN_GROUP =
'group'
- TOKEN_TEXT =
'text'
Instance Method Summary collapse
- #get_token ⇒ Object
-
#initialize(buffer) ⇒ RTFReader
constructor
A new instance of RTFReader.
Constructor Details
#initialize(buffer) ⇒ RTFReader
Returns a new instance of RTFReader.
21 22 23 24 |
# File 'lib/oddb/redist/rtf_tools/reader.rb', line 21 def initialize(buffer) @bufferstring = buffer @buffer = Array.new end |
Instance Method Details
#get_token ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/oddb/redist/rtf_tools/reader.rb', line 28 def get_token @token = '' @body = '' @extra = '' chr = _read_char if not chr then @token = TOKEN_EOF else @body << chr case chr when '{', '}' @token = TOKEN_GROUP when '\\' chr = _read_char @body << chr if chr =~ /[a-zA-Z]/ then @token = TOKEN_CONTROL process_control else @token = TOKEN_TEXT process_text end else @token = TOKEN_TEXT process_text end end if @token == TOKEN_CONTROL and @body =~ /^(\\[a-zA-Z]+)(.*)$/ then @body = $1 @extra = $2 end return @token, @body, @extra end |