Class: ElasticTabstops::Formatter
- Inherits:
-
Object
- Object
- ElasticTabstops::Formatter
- Defined in:
- lib/elastic_tabstops/formatter.rb
Instance Method Summary collapse
-
#initialize(output_stream, tabchar: "\t", padchar: ' ') ⇒ Formatter
constructor
A new instance of Formatter.
-
#line(text) ⇒ Object
PRECONDITION: text == ” || /A.*r?nz/ === text In the regex above, ‘A` matches beginning-of-string, and `z` matches end-of-string.
Constructor Details
#initialize(output_stream, tabchar: "\t", padchar: ' ') ⇒ Formatter
Returns a new instance of Formatter.
4 5 6 7 8 9 10 11 |
# File 'lib/elastic_tabstops/formatter.rb', line 4 def initialize(output_stream, tabchar: "\t", padchar: ' ') @outstream = output_stream @lines = [] @ctrls = [] @tabchar = tabchar @padchar = padchar @split_re = /(?<=#{Regexp.escape(tabchar)})/ end |
Instance Method Details
#line(text) ⇒ Object
PRECONDITION: text == ” || /A.*r?nz/ === text In the regex above, ‘A` matches beginning-of-string, and `z` matches end-of-string. The absence of a multiline modifier (as in /abc/m) means `.` does NOT match newline.
So, in English: ‘text` is a string, and it is either the empty string, or it is a sequence of non-newline characters terminated by a newline.
20 21 22 23 24 25 26 27 |
# File 'lib/elastic_tabstops/formatter.rb', line 20 def line(text) texts = text.split(@split_re) # Ensure that a non-tab-terminated text exists at the end of texts texts << '' if texts.empty? || texts[-1][-1] == @tabchar emit_line_of_cells(texts) end |