Class: SSE::Impl::EventParser
- Inherits:
-
Object
- Object
- SSE::Impl::EventParser
- Defined in:
- lib/ld-eventsource/impl/event_parser.rb
Overview
Accepts lines of text via an enumerator, and parses them into SSE messages. You will not need to use this directly if you are using Client, but it may be useful for testing.
Instance Method Summary collapse
-
#initialize(lines) ⇒ EventParser
constructor
Constructs an instance of EventParser.
-
#items ⇒ Object
Generator that parses the input iterator and returns instances of StreamEvent or SetRetryInterval.
Constructor Details
#initialize(lines) ⇒ EventParser
Constructs an instance of EventParser.
25 26 27 28 |
# File 'lib/ld-eventsource/impl/event_parser.rb', line 25 def initialize(lines) @lines = lines reset_buffers end |
Instance Method Details
#items ⇒ Object
Generator that parses the input iterator and returns instances of StreamEvent or SetRetryInterval.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ld-eventsource/impl/event_parser.rb', line 31 def items Enumerator.new do |gen| @lines.each do |line| line.chomp! if line.empty? event = maybe_create_event reset_buffers gen.yield event if !event.nil? else case line when /^(\w+): ?(.*)$/ item = process_field($1, $2) gen.yield item if !item.nil? end end end end end |