Class: Faker::Bot::Renderer Private
- Inherits:
-
Object
- Object
- Faker::Bot::Renderer
- Defined in:
- lib/faker/bot/renderer.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.
A class responsible for printing output to an [IO] interface
Constant Summary collapse
- DEPRECATION_WARNING =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
' ( WILL BE DEPRECATED )'
- EMPTY =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
''
- NOT_AVAILABLE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'N/A'
Instance Attribute Summary collapse
- #crayon ⇒ Object readonly private
- #hash ⇒ Object readonly private
- #options ⇒ Object readonly private
- #output ⇒ Object readonly private
- #pager ⇒ Object readonly private
Class Method Summary collapse
- .call(*args) ⇒ Object private
Instance Method Summary collapse
-
#call ⇒ IO
private
Print paginated output if the terminal interface supports pagination.
-
#gt_screen_height? ⇒ Boolean
private
Check whether the tree size is greater than current screen height.
-
#initialize(hash, options, output) ⇒ Renderer
constructor
Initialize a Render.
-
#paginable? ⇒ Boolean
private
Check whether the terminal interface supports pagination.
-
#render ⇒ String
private
Render the structured data tree.
-
#tree ⇒ TTY<Tree>
private
Warm up the structured data tree render object.
Constructor Details
#initialize(hash, options, output) ⇒ Renderer
Initialize a Render
33 34 35 36 37 38 39 40 |
# File 'lib/faker/bot/renderer.rb', line 33 def initialize(hash, , output) @hash = hash @options = @output = output @crayon = Pastel.new(enabled: output.tty?) @pager = TTY::Pager.new(command: 'less -R') end |
Instance Attribute Details
#crayon ⇒ Object (readonly)
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.
19 20 21 |
# File 'lib/faker/bot/renderer.rb', line 19 def crayon @crayon end |
#hash ⇒ Object (readonly)
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.
19 20 21 |
# File 'lib/faker/bot/renderer.rb', line 19 def hash @hash end |
#options ⇒ Object (readonly)
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.
19 20 21 |
# File 'lib/faker/bot/renderer.rb', line 19 def @options end |
#output ⇒ Object (readonly)
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.
19 20 21 |
# File 'lib/faker/bot/renderer.rb', line 19 def output @output end |
#pager ⇒ Object (readonly)
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.
19 20 21 |
# File 'lib/faker/bot/renderer.rb', line 19 def pager @pager end |
Class Method Details
.call(*args) ⇒ Object
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.
21 22 23 |
# File 'lib/faker/bot/renderer.rb', line 21 def self.call(*args) new(*args).call end |
Instance Method Details
#call ⇒ IO
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.
Print paginated output if the terminal interface supports pagination. Otherwise, just print the full output
49 50 51 52 53 54 55 |
# File 'lib/faker/bot/renderer.rb', line 49 def call if paginable? pager.page(render) else output.puts(render) end end |
#gt_screen_height? ⇒ Boolean
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.
Check whether the tree size is greater than current screen height
93 94 95 |
# File 'lib/faker/bot/renderer.rb', line 93 def gt_screen_height? tree.nodes.size > TTY::Screen.height end |
#paginable? ⇒ Boolean
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.
Check whether the terminal interface supports pagination
83 84 85 |
# File 'lib/faker/bot/renderer.rb', line 83 def paginable? gt_screen_height? && output.tty? end |
#render ⇒ String
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.
Render the structured data tree
63 64 65 |
# File 'lib/faker/bot/renderer.rb', line 63 def render tree.render end |
#tree ⇒ TTY<Tree>
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.
Warm up the structured data tree render object
73 74 75 |
# File 'lib/faker/bot/renderer.rb', line 73 def tree @tree ||= TTY::Tree.new(build_tree) end |