Class: FakerBot::Renderer
- Inherits:
-
Object
- Object
- FakerBot::Renderer
- Defined in:
- lib/fakerbot/renderer.rb
Instance Attribute Summary collapse
-
#crayon ⇒ Object
readonly
Returns the value of attribute crayon.
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#pager ⇒ Object
readonly
Returns the value of attribute pager.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
- #gt_screen_height? ⇒ Boolean
-
#initialize(hash, options, output) ⇒ Renderer
constructor
A new instance of Renderer.
- #paginable? ⇒ Boolean
- #render ⇒ Object
- #tree ⇒ Object
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, , 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)
Returns the value of attribute crayon.
10 11 12 |
# File 'lib/fakerbot/renderer.rb', line 10 def crayon @crayon end |
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
10 11 12 |
# File 'lib/fakerbot/renderer.rb', line 10 def hash @hash end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/fakerbot/renderer.rb', line 10 def @options end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
10 11 12 |
# File 'lib/fakerbot/renderer.rb', line 10 def output @output end |
#pager ⇒ Object (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
#call ⇒ Object
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
44 45 46 |
# File 'lib/fakerbot/renderer.rb', line 44 def gt_screen_height? tree.nodes.size > TTY::Screen.height end |
#paginable? ⇒ Boolean
40 41 42 |
# File 'lib/fakerbot/renderer.rb', line 40 def paginable? gt_screen_height? && output.tty? end |
#render ⇒ Object
32 33 34 |
# File 'lib/fakerbot/renderer.rb', line 32 def render tree.render end |
#tree ⇒ Object
36 37 38 |
# File 'lib/fakerbot/renderer.rb', line 36 def tree @tree ||= TTY::Tree.new(build_tree) end |