Class: CARPS::MessageParser
- Inherits:
-
Object
- Object
- CARPS::MessageParser
- Defined in:
- lib/carps/protocol/message.rb
Overview
Parse a message from a block of unformatted text
Instance Method Summary collapse
-
#choose_parser(blob) ⇒ Object
Parse, choosing from a number of alternative messages, return the first one that suceeds.
-
#initialize(choices) ⇒ MessageParser
constructor
Create a new parser from a list of choices.
-
#parse(text) ⇒ Object
Parse the text into a message.
Constructor Details
#initialize(choices) ⇒ MessageParser
Create a new parser from a list of choices
32 33 34 |
# File 'lib/carps/protocol/message.rb', line 32 def initialize choices @choices = choices end |
Instance Method Details
#choose_parser(blob) ⇒ Object
Parse, choosing from a number of alternative messages, return the first one that suceeds
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/carps/protocol/message.rb', line 37 def choose_parser blob @choices.each do || begin result, text = .parse blob return [result, text] rescue Expected end end raise Expected end |