Class: FakerBot::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/fakerbot/renderer.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash, options, output) ⇒ Renderer

Returns a new instance of Renderer.



14
15
16
17
18
19
20
21
22
# File 'lib/fakerbot/renderer.rb', line 14

def initialize(hash, options, output)
  @hash = hash
  @options = options
  @output = output
  @crayon = Pastel.new(enabled: output.tty?)
  @pager = TTY::Pager.new(command: 'less -R')
  @screen = TTY::Screen
  @tree = TTY::Tree
end

Class Method Details

.call(hash, options, output) ⇒ Object



10
11
12
# File 'lib/fakerbot/renderer.rb', line 10

def self.call(hash, options, output)
  new(hash, options, output).call
end

Instance Method Details

#callObject



24
25
26
27
28
29
30
31
32
# File 'lib/fakerbot/renderer.rb', line 24

def call
  data_tree = tree.new(build_tree)
  view = data_tree.render
  if gt_screen_height?(data_tree)
    output.tty? ? pager.page(view) : output.puts(view)
  else
    output.puts view
  end
end