Class: Zpl::Reader
- Inherits:
-
Object
- Object
- Zpl::Reader
- Defined in:
- lib/zpl-transformer/reader.rb
Overview
NOTE: doesn’t handle ZPL that changes the control char (default is assumed: ‘^’)
Instance Method Summary collapse
-
#each_command ⇒ Object
Yields each ZPL command to the block.
-
#initialize(content, strip_spaces: true) ⇒ Reader
constructor
Creates a new reader that will read ZPL commands from content string.
-
#next_command ⇒ Object
Returns the next zpl command if any, or nil.
-
#next_token ⇒ Object
Returns the next zpl command or ignored string if any, or nil.
Constructor Details
#initialize(content, strip_spaces: true) ⇒ Reader
Creates a new reader that will read ZPL commands from content string.
10 11 12 13 |
# File 'lib/zpl-transformer/reader.rb', line 10 def initialize(content, strip_spaces: true) @scanner = StringScanner.new content @strip_spaces = strip_spaces end |
Instance Method Details
#each_command ⇒ Object
Yields each ZPL command to the block. Stops when there are no more commands to read.
40 41 42 43 44 |
# File 'lib/zpl-transformer/reader.rb', line 40 def each_command while cmd = next_command yield cmd end end |
#next_command ⇒ Object
Returns the next zpl command if any, or nil.
29 30 31 32 33 34 35 36 37 |
# File 'lib/zpl-transformer/reader.rb', line 29 def next_command while token = next_token if token.is_a?(Command) return token end end nil end |
#next_token ⇒ Object
Returns the next zpl command or ignored string if any, or nil.
The ignored string can be a newlines, ignored chars, spaces or unsupported syntax.
18 19 20 21 22 23 24 25 26 |
# File 'lib/zpl-transformer/reader.rb', line 18 def next_token return if @scanner.eos? if chars_to_ignore = parse_ignore_chars return chars_to_ignore end parse_zpl_cmd end |