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 collapse
- #options ⇒ Hash<Symbol => void> included from Options
Instance Method Summary collapse
-
#absent?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable is nil or empty.
-
#become(klass, attributes) ⇒ Class
included
from Common
private
Converts one class into another.
-
#boolean(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating the value was a boolean.
-
#boolean?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Boolean.
- #buffer ⇒ Array<String> private
-
#clear ⇒ String
Render a cleared output.
-
#compression ⇒ String
included
from Options
private
Compresses the output depending on configuration.
-
#compression? ⇒ Boolean
included
from Options
private
Returns a boolean indicating whether the content should be compressed if compression is available.
-
#content ⇒ String
private
Combine all characters in a row to produce a line, then all lines should be terminated with ‘n`.
- #default_template ⇒ String included from Options private
-
#defaults ⇒ Hash<Symbol => void>
included
from Options
private
The default values for a new instance of this class.
- #end_row_tag ⇒ String included from Options private
- #end_tag ⇒ String included from Options private
-
#escape?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is an escape sequence object (e.g. Cells::Escape.).
-
#falsy?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value should be considered false.
-
#filename ⇒ String
included
from Options
private
Return the filename given in the options, (or use the default), and append a timestamp if the :timestamp option was set to true.
-
#hash?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Hash.
-
#initialize(opts = {}) ⇒ void
included
from Options
Returns a new instance of the class including this module.
-
#line_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::Line.
-
#numeric?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
- #output ⇒ void included from Options private
- #output? ⇒ Boolean included from Options private
- #positionable?(char) ⇒ Boolean private
-
#present?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable has a useful value.
- #render(output = '') ⇒ void included from Options
- #renderable?(char) ⇒ Boolean private
- #renderables ⇒ Array<Class> private
-
#snake_case(klass) ⇒ String
included
from Common
private
Converts a class name to a lowercase snake case string.
- #start_row_tag ⇒ String included from Options private
- #start_tag ⇒ String included from Options private
-
#stream_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::Stream.
-
#string?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
- #template ⇒ String included from Options private
- #textual?(char) ⇒ Boolean private
-
#timestamp ⇒ String
included
from Options
private
Return a timestamp for use as part of the filename if the :timestamp option was set to true, otherwise an empty string.
- #timestamp? ⇒ Boolean included from Options private
-
#truthy?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value should be considered true.
-
#view_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::View.
- #write ⇒ Object included from Options
-
#write_file ⇒ String
included
from Options
private
Render the output (either content or clearing) to a file.
-
#write_file? ⇒ Boolean
included
from Options
private
Returns a boolean indicating whether a file should be written.
Instance Attribute Details
#options ⇒ Hash<Symbol => void> Originally defined in module Options
Instance Method Details
#absent?(variable) ⇒ Boolean Originally defined in module Common
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 a boolean indicating whether a variable is nil or empty.
#become(klass, attributes) ⇒ Class Originally defined in module Common
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.
Converts one class into another.
#boolean(value) ⇒ Boolean Originally defined in module Common
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 a boolean indicating the value was a boolean.
#boolean?(value) ⇒ Boolean Originally defined in module Common
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 a boolean indicating whether the value is a Boolean.
#buffer ⇒ Array<String> (private)
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/vedeu/renderers/text.rb', line 39 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 |
#clear ⇒ String
Render a cleared output.
18 19 20 |
# File 'lib/vedeu/renderers/text.rb', line 18 def clear render('') end |
#compression ⇒ String (private) Originally defined in module Options
Compresses the output depending on configuration.
#compression? ⇒ Boolean (private) Originally defined in module Options
Returns a boolean indicating whether the content should be compressed if compression is available.
#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.
30 31 32 33 34 35 36 |
# File 'lib/vedeu/renderers/text.rb', line 30 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 |
#default_template ⇒ String (private) Originally defined in module Options
#defaults ⇒ Hash<Symbol => void> (private) Originally defined in module Options
The default values for a new instance of this class.
#end_row_tag ⇒ String (private) Originally defined in module Options
#end_tag ⇒ String (private) Originally defined in module Options
#escape?(value) ⇒ Boolean Originally defined in module Common
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 a boolean indicating whether the value is an escape sequence object (e.g. Vedeu::Cells::Escape.)
#falsy?(value) ⇒ Boolean Originally defined in module Common
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 a boolean indicating whether the value should be considered false.
#filename ⇒ String (private) Originally defined in module Options
Return the filename given in the options, (or use the default), and append a timestamp if the :timestamp option was set to true.
#hash?(value) ⇒ Boolean Originally defined in module Common
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 a boolean indicating whether the value is a Hash.
#initialize(opts = {}) ⇒ void Originally defined in module Options
Returns a new instance of the class including this module.
#line_model? ⇒ Boolean Originally defined in module Common
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 a boolean indicating the model is a Views::Line.
#numeric?(value) ⇒ Boolean Originally defined in module Common
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 a boolean indicating whether the value is a Fixnum.
#output ⇒ void (private) Originally defined in module Options
This method returns an undefined value.
#positionable?(char) ⇒ Boolean (private)
56 57 58 59 |
# File 'lib/vedeu/renderers/text.rb', line 56 def positionable?(char) char.respond_to?(:position) && char.position.is_a?(Vedeu::Geometries::Position) end |
#present?(variable) ⇒ Boolean Originally defined in module Common
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 a boolean indicating whether a variable has a useful value.
#render(output = '') ⇒ void Originally defined in module Options
This method returns an undefined value.
#renderable?(char) ⇒ Boolean (private)
83 84 85 |
# File 'lib/vedeu/renderers/text.rb', line 83 def renderable?(char) renderables.include?(char.class) end |
#renderables ⇒ Array<Class> (private)
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/vedeu/renderers/text.rb', line 62 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 |
#snake_case(klass) ⇒ String Originally defined in module Common
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.
Converts a class name to a lowercase snake case string.
#start_row_tag ⇒ String (private) Originally defined in module Options
#start_tag ⇒ String (private) Originally defined in module Options
#stream_model? ⇒ Boolean Originally defined in module Common
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 a boolean indicating the model is a Views::Stream.
#string?(value) ⇒ Boolean Originally defined in module Common
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 a boolean indicating whether the value is a Fixnum.
#template ⇒ String (private) Originally defined in module Options
#textual?(char) ⇒ Boolean (private)
88 89 90 |
# File 'lib/vedeu/renderers/text.rb', line 88 def textual?(char) char.respond_to?(:text) end |
#timestamp ⇒ String (private) Originally defined in module Options
Return a timestamp for use as part of the filename if the :timestamp option was set to true, otherwise an empty string.
#truthy?(value) ⇒ Boolean Originally defined in module Common
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 a boolean indicating whether the value should be considered true.
#view_model? ⇒ Boolean Originally defined in module Common
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 a boolean indicating the model is a Views::View.
#write ⇒ Object Originally defined in module Options
#write_file ⇒ String (private) Originally defined in module Options
Render the output (either content or clearing) to a file.