class SNMPTableViewer::Formatter::JSON
Formatting class for JSON
output
Public Instance Methods
output()
click to toggle source
Output the data. If no headings are provided you'll get an Array or Arrays. If headings are provided you'll get an Array of Hashes. @return [String] the JSON
data
# File lib/snmp_table_viewer/formatter/json.rb, line 7 def output() data = @data if @headings.size > 0 # Convert inner arrays to hashes data = data.map{ |row| Hash[row.map.with_index{ |value, index| [@headings[index] || '', value] }] } end ::JSON.generate(data) end