Class: TTYString::Parser
- Inherits:
-
StringScanner
- Object
- StringScanner
- TTYString::Parser
- Defined in:
- lib/tty_string/parser.rb
Overview
Reads the text string a
Instance Attribute Summary collapse
-
#screen ⇒ Object
readonly
Returns the value of attribute screen.
-
#style_handler ⇒ Object
readonly
Returns the value of attribute style_handler.
Instance Method Summary collapse
- #cursor ⇒ Object
- #initial_style ⇒ Object
-
#render(style:, unknown:) ⇒ Object
rubocop:disable Metrics/MethodLength.
-
#unknown ⇒ Object
rubocop:disable Metrics/MethodLength.
Instance Attribute Details
#screen ⇒ Object (readonly)
Returns the value of attribute screen.
13 14 15 |
# File 'lib/tty_string/parser.rb', line 13 def screen @screen end |
#style_handler ⇒ Object (readonly)
Returns the value of attribute style_handler.
13 14 15 |
# File 'lib/tty_string/parser.rb', line 13 def style_handler @style_handler end |
Instance Method Details
#cursor ⇒ Object
25 26 27 |
# File 'lib/tty_string/parser.rb', line 25 def cursor screen.cursor end |
#initial_style ⇒ Object
43 44 45 46 47 48 |
# File 'lib/tty_string/parser.rb', line 43 def initial_style @initial_style ||= case style_handler when RENDER then Style.new(parser: self) else NullStyle end end |
#render(style:, unknown:) ⇒ Object
rubocop:disable Metrics/MethodLength
15 16 17 18 19 20 21 22 23 |
# File 'lib/tty_string/parser.rb', line 15 def render(style:, unknown:) # rubocop:disable Metrics/MethodLength @style_handler = style @unknown_handler = unknown reset @screen = Screen.new(initial_style: initial_style) read until eos? screen.to_s end |
#unknown ⇒ Object
rubocop:disable Metrics/MethodLength
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/tty_string/parser.rb', line 29 def unknown # rubocop:disable Metrics/MethodLength case unknown_handler when RAISE raise( UnknownCodeError, if block_given? yield(matched) else "Unknown code #{matched.inspect}" end ) end end |