class SNMPTableViewer::Formatter

Parent class for formatters. Which take data and headings and output it in a given format. @abstract

Public Class Methods

new(data:, headings: []) click to toggle source

Create a new instance of Formatter. @param data [Array<Array<#to_s>>] A two dimensional array containing objects in each cell (at 'address' data[col]) @param headings [Array<String, to_s>] An array of headings for each column @return [Formatter]

# File lib/snmp_table_viewer/formatter.rb, line 11
def initialize(data:, headings: [])
    @headings = headings
    @data = data
end

Private Instance Methods

data_with_headings() click to toggle source

Get a two dimensioan array of headings prepended to the data or just the data (if no headings were provided). @return Array<Array<#to_s>>

# File lib/snmp_table_viewer/formatter.rb, line 19
def data_with_headings
  has_headings? ? [@headings, *@data] : @data
end
has_headings?() click to toggle source

Determine if headings were passed. @return [Boolean]

# File lib/snmp_table_viewer/formatter.rb, line 24
def has_headings?
  @headings.is_a?(Array) && @headings.size > 0
end