Class: BioSyntax::Highlighter
- Inherits:
-
Object
- Object
- BioSyntax::Highlighter
- Defined in:
- lib/biosyntax.rb
Overview
Stateful highlighter for one input format.
Reuse one highlighter for one logical input stream. Some formats, such as FASTQ and WIG, need line-to-line state. Call #reset before reusing the object for another stream.
Instance Attribute Summary collapse
-
#format ⇒ Format
readonly
Format metadata for this highlighter.
Instance Method Summary collapse
-
#colorize(line) ⇒ String
(also: #colorize_line, #render_ansi, #render_ansi_line)
Highlight one input line and return ANSI-colored text.
-
#format_name ⇒ Symbol
Canonical format name.
-
#highlight(line) ⇒ Array<Span>
(also: #highlight_line)
Highlight one input line and return semantic spans.
-
#initialize(format) ⇒ Highlighter
constructor
A new instance of Highlighter.
- #inspect ⇒ String
-
#line_no ⇒ Integer
Number of lines processed since initialization or the last reset.
-
#reset ⇒ Highlighter
Reset line-oriented parser state.
-
#stateful? ⇒ Boolean
True when this format depends on previous lines.
Constructor Details
Instance Attribute Details
#format ⇒ Format (readonly)
Returns format metadata for this highlighter.
283 284 285 |
# File 'lib/biosyntax.rb', line 283 def format @format end |
Instance Method Details
#colorize(line) ⇒ String Also known as: colorize_line, render_ansi, render_ansi_line
Highlight one input line and return ANSI-colored text.
310 311 312 |
# File 'lib/biosyntax.rb', line 310 def colorize(line) @state.colorize(line) end |
#format_name ⇒ Symbol
Returns canonical format name.
293 294 295 |
# File 'lib/biosyntax.rb', line 293 def format_name @format.name end |
#highlight(line) ⇒ Array<Span> Also known as: highlight_line
Highlight one input line and return semantic spans.
301 302 303 |
# File 'lib/biosyntax.rb', line 301 def highlight(line) @state.highlight(line) end |
#inspect ⇒ String
338 339 340 |
# File 'lib/biosyntax.rb', line 338 def inspect "#<#{self.class} format=#{format_name.inspect} line_no=#{line_no}>" end |
#line_no ⇒ Integer
Number of lines processed since initialization or the last reset.
328 329 330 |
# File 'lib/biosyntax.rb', line 328 def line_no @state.line_no end |
#reset ⇒ Highlighter
Reset line-oriented parser state.
320 321 322 323 |
# File 'lib/biosyntax.rb', line 320 def reset @state.reset(@format.id) self end |
#stateful? ⇒ Boolean
Returns true when this format depends on previous lines.
333 334 335 |
# File 'lib/biosyntax.rb', line 333 def stateful? @format.stateful? end |