Class: SGF::Stream
- Inherits:
-
Object
- Object
- SGF::Stream
- Defined in:
- lib/sgf/stream.rb
Instance Attribute Summary collapse
-
#stream ⇒ Object
readonly
Returns the value of attribute stream.
Instance Method Summary collapse
- #eof? ⇒ Boolean
-
#initialize(sgf, error_checker) ⇒ Stream
constructor
A new instance of Stream.
- #next_character ⇒ Object
- #peek_skipping_whitespace ⇒ Object
- #read_token(format) ⇒ Object
Constructor Details
#initialize(sgf, error_checker) ⇒ Stream
Returns a new instance of Stream.
6 7 8 9 10 11 |
# File 'lib/sgf/stream.rb', line 6 def initialize sgf, error_checker sgf = sgf.read if sgf.instance_of?(File) sgf = File.read(sgf) if File.exist?(sgf) error_checker.check_for_errors_before_parsing sgf @stream = StringIO.new clean(sgf), 'r' end |
Instance Attribute Details
#stream ⇒ Object (readonly)
Returns the value of attribute stream.
4 5 6 |
# File 'lib/sgf/stream.rb', line 4 def stream @stream end |
Instance Method Details
#eof? ⇒ Boolean
13 14 15 |
# File 'lib/sgf/stream.rb', line 13 def eof? stream.eof? end |
#next_character ⇒ Object
17 18 19 |
# File 'lib/sgf/stream.rb', line 17 def next_character !stream.eof? && stream.sysread(1) end |
#peek_skipping_whitespace ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/sgf/stream.rb', line 29 def peek_skipping_whitespace while char = next_character next if char[/\s/] break end rewind if char char end |
#read_token(format) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/sgf/stream.rb', line 21 def read_token format property = "" while char = next_character and format.still_inside? char, property, self property << char end format.transform property end |