Class: Vedeu::Renderers::Text
- Includes:
- Options
- Defined in:
- lib/vedeu/renderers/text.rb
Overview
Converts a grid of Cells objects or Cells::Char objects into a stream of characters without escape sequences.
Instance Attribute Summary
Attributes included from Options
Instance Method Summary collapse
- #buffer ⇒ Array<String> private
-
#content ⇒ String
private
Combine all characters in a row to produce a line, then all lines should be terminated with ‘n`.
- #renderable?(char) ⇒ Boolean private
- #renderables ⇒ Array<Class> private
- #textual?(char) ⇒ Boolean private
Methods included from Options
#clear, #compression, #compression?, #default_template, #defaults, #end_row_tag, #end_tag, #filename, #initialize, #output, #output?, #render, #start_row_tag, #start_tag, #template, #timestamp, #timestamp?, #write, #write_file, #write_file?
Methods included from Common
#absent?, #array?, #boolean, #boolean?, #empty_value?, #escape?, #falsy?, #hash?, #line_model?, #numeric?, #positionable?, #present?, #snake_case, #stream_model?, #string?, #symbol?, #truthy?, #view_model?
Methods inherited from File
Instance Method Details
#buffer ⇒ Array<String> (private)
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/vedeu/renderers/text.rb', line 32 def buffer empty = Array.new(Vedeu.height) { Array.new(Vedeu.width) { ' ' } } output.each do |row| row.each do |char| next unless renderable?(char) && positionable?(char) && textual?(char) empty[char.position.y - 1][char.position.x - 1] = char.text end end empty end |
#content ⇒ String (private)
Combine all characters in a row to produce a line, then all lines should be terminated with ‘n`. Convert to an array of UTF8 codepoints, and any codepoint above 255 should be converted to a space.
23 24 25 26 27 28 29 |
# File 'lib/vedeu/renderers/text.rb', line 23 def content return '' if string?(output) || absent?(output) buffer.map(&:join).join("\n").unpack('U*').map do |c| (c > 255) ? ' ' : c.chr end.join end |
#renderable?(char) ⇒ Boolean (private)
70 71 72 |
# File 'lib/vedeu/renderers/text.rb', line 70 def renderable?(char) renderables.include?(char.class) end |
#renderables ⇒ Array<Class> (private)
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/vedeu/renderers/text.rb', line 49 def renderables [ Vedeu::Cells::Border, Vedeu::Cells::BottomHorizontal, Vedeu::Cells::BottomLeft, Vedeu::Cells::BottomRight, Vedeu::Cells::Corner, Vedeu::Cells::Char, Vedeu::Cells::Clear, Vedeu::Cells::Empty, Vedeu::Cells::Horizontal, Vedeu::Cells::LeftVertical, Vedeu::Cells::RightVertical, Vedeu::Cells::TopHorizontal, Vedeu::Cells::TopLeft, Vedeu::Cells::TopRight, Vedeu::Cells::Vertical, ] end |
#textual?(char) ⇒ Boolean (private)
75 76 77 |
# File 'lib/vedeu/renderers/text.rb', line 75 def textual?(char) char.respond_to?(:text) end |