Class: Faker::Bot::Renderer Private

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash, options, output) ⇒ Renderer

Initialize a Render

Parameters:

  • hash (Hash<Class => <Array<Symbol>>])

    ash [Hash<Class => <Array<Symbol>>]

  • options (Hash)
  • output (IO)


33
34
35
36
37
38
39
40
# File 'lib/faker/bot/renderer.rb', line 33

def initialize(hash, options, output)
  @hash = hash
  @options = options
  @output = output

  @crayon = Pastel.new(enabled: output.tty?)
  @pager = TTY::Pager.new(command: 'less -R')
end

Instance Attribute Details

#crayonObject (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

#hashObject (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

#optionsObject (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
  @options
end

#outputObject (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

#pagerObject (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

#callIO

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

Returns:

  • (IO)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


83
84
85
# File 'lib/faker/bot/renderer.rb', line 83

def paginable?
  gt_screen_height? && output.tty?
end

#renderString

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

Returns:

  • (String)


63
64
65
# File 'lib/faker/bot/renderer.rb', line 63

def render
  tree.render
end

#treeTTY<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

Returns:

  • (TTY<Tree>)


73
74
75
# File 'lib/faker/bot/renderer.rb', line 73

def tree
  @tree ||= TTY::Tree.new(build_tree)
end