Class: FakerBot::Renderer

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash, options, output) ⇒ Renderer

Returns a new instance of Renderer.



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

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)

Returns the value of attribute crayon.



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

def crayon
  @crayon
end

#hashObject (readonly)

Returns the value of attribute hash.



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

def hash
  @hash
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#outputObject (readonly)

Returns the value of attribute output.



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

def output
  @output
end

#pagerObject (readonly)

Returns the value of attribute pager.



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

def pager
  @pager
end

Class Method Details

.call(*args) ⇒ Object



12
13
14
# File 'lib/fakerbot/renderer.rb', line 12

def self.call(*args)
  new(*args).call
end

Instance Method Details

#callObject



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

def call
  if paginable?
    pager.page(render)
  else
    output.puts(render)
  end
end

#gt_screen_height?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/fakerbot/renderer.rb', line 44

def gt_screen_height?
  tree.nodes.size > TTY::Screen.height
end

#paginable?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/fakerbot/renderer.rb', line 40

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

#renderObject



32
33
34
# File 'lib/fakerbot/renderer.rb', line 32

def render
  tree.render
end

#treeObject



36
37
38
# File 'lib/fakerbot/renderer.rb', line 36

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