Class: Nazar::View

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/nazar/view.rb

Instance Method Summary collapse

Constructor Details

#initialize(data, layout:, use_generic_formatter: false) ⇒ View

Returns a new instance of View.



9
10
11
12
13
# File 'lib/nazar/view.rb', line 9

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

Instance Method Details

#horizontal?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/nazar/view.rb', line 40

def horizontal?
  layout == :horizontal
end

#layoutObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/nazar/view.rb', line 27

def layout
  case @layout
  when :auto
    determine_layout
  when :vertical
    :vertical
  when :horizontal
    :horizontal
  else
    raise ArgumentError, "Unknown layout: #{Nazar.config.formatter.layout}"
  end
end

#renderObject



15
16
17
18
19
20
21
# File 'lib/nazar/view.rb', line 15

def render
  return unless supported_data?

  table.add_summary(summary) if summary

  table.render
end

#supported_data?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/nazar/view.rb', line 23

def supported_data?
  !!formatter_klass && formatter.valid?
end