Class: Nazar::Renderer

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

Instance Method Summary collapse

Constructor Details

#initialize(data, layout:, paginate:, use_generic_formatter: false) ⇒ Renderer

Returns a new instance of Renderer.



5
6
7
8
9
10
# File 'lib/nazar/renderer.rb', line 5

def initialize(data, layout:, paginate:, use_generic_formatter: false)
  @data = data
  @use_generic_formatter = use_generic_formatter
  @layout = layout
  @paginate = paginate
end

Instance Method Details

#pagerObject



25
26
27
# File 'lib/nazar/renderer.rb', line 25

def pager
  @pager ||= TTY::Pager::SystemPager.new(command: 'less -iMSx4 -FXR')
end

#renderObject



12
13
14
15
16
17
18
19
# File 'lib/nazar/renderer.rb', line 12

def render
  if paginate || view.horizontal?
    pager.page(view.render)
  else
    puts view.render
  end
  nil
end

#valid?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/nazar/renderer.rb', line 21

def valid?
  view.supported_data?
end