Class: Codeball::Stream
- Inherits:
-
Object
- Object
- Codeball::Stream
- Includes:
- Enumerable
- Defined in:
- lib/codeball/stream.rb
Overview
Assembles Entry objects from a stream of tokens produced by Cursor.
Stream pulls tokens one at a time, feeds them to the current Entry, and emits it when Entry reports valid or errored. Stream does not know the Header -> Body -> Footer rules – Entry enforces those through its write-once setters.
Nothing is discarded. Every entry – valid, errored, or truncated – is emitted so the consumer can decide what to do with it.
Instance Method Summary collapse
- #each(&block) ⇒ Object (also: #each_entry)
-
#initialize(cursor:) ⇒ Stream
constructor
A new instance of Stream.
Constructor Details
#initialize(cursor:) ⇒ Stream
Returns a new instance of Stream.
15 16 17 18 |
# File 'lib/codeball/stream.rb', line 15 def initialize(cursor:) @cursor = cursor new_entry end |
Instance Method Details
#each(&block) ⇒ Object Also known as: each_entry
20 21 22 23 24 25 |
# File 'lib/codeball/stream.rb', line 20 def each(&block) return enum_for(:each) unless block consume_tokens(&block) emit_incomplete(&block) end |