Class: Accessibility::Keyboard::Parser
- Inherits:
-
Object
- Object
- Accessibility::Keyboard::Parser
- Defined in:
- lib/accessibility/keyboard/parser.rb
Overview
Parse arbitrary strings into a stream of keyboard events
This class will take a string and break it up into chunks for the keyboard event generator. The structure generated here is an array that contains strings and recursively other arrays of strings and arrays of strings.
Instance Attribute Summary collapse
-
#tokens ⇒ Array<String,Array<String,...>]
Once a string is parsed, this contains the tokenized structure.
Instance Method Summary collapse
-
#initialize(string) ⇒ Parser
constructor
A new instance of Parser.
-
#parse ⇒ Array<String,Array<String,...>]
Tokenize the string that the parser was initialized with and return the sequence of tokens that were parsed.
Constructor Details
#initialize(string) ⇒ Parser
Returns a new instance of Parser.
26 27 28 29 |
# File 'lib/accessibility/keyboard/parser.rb', line 26 def initialize string @chars = string.to_s @tokens = [] end |
Instance Attribute Details
#tokens ⇒ Array<String,Array<String,...>]
Once a string is parsed, this contains the tokenized structure.
23 24 25 |
# File 'lib/accessibility/keyboard/parser.rb', line 23 def tokens @tokens end |
Instance Method Details
#parse ⇒ Array<String,Array<String,...>]
Tokenize the string that the parser was initialized with and return the sequence of tokens that were parsed.
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/accessibility/keyboard/parser.rb', line 36 def parse length = @chars.length @index = 0 while @index < length @tokens << if custom? parse_custom else parse_char end @index += 1 end @tokens end |