Class: Vedeu::Renderers::Text Private

Inherits:
File
  • Object
show all
Includes:
Options
Defined in:
lib/vedeu/renderers/text.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

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

#options

Instance Method Summary collapse

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

#write, #write_file?

Instance Method Details

#bufferArray<String> (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Array<String>)


34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/vedeu/renderers/text.rb', line 34

def buffer
  empty = Array.new(Vedeu.height) { Array.new(Vedeu.width) { ' ' } }

  output.each do |row|
    row.each do |char|
      next unless positionable?(char)

      empty[char.position.y - 1][char.position.x - 1] = char.text
    end
  end

  empty
end

#contentString (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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.

Returns:

  • (String)


25
26
27
28
29
30
31
# File 'lib/vedeu/renderers/text.rb', line 25

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