Class: SNMPTableViewer::Formatter::JSON
- Inherits:
-
SNMPTableViewer::Formatter
- Object
- SNMPTableViewer::Formatter
- SNMPTableViewer::Formatter::JSON
- Defined in:
- lib/snmp_table_viewer/formatter/json.rb
Overview
Formatting class for JSON output
Instance Method Summary collapse
-
#output ⇒ String
Output the data.
Methods inherited from SNMPTableViewer::Formatter
Constructor Details
This class inherits a constructor from SNMPTableViewer::Formatter
Instance Method Details
#output ⇒ String
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.
7 8 9 10 11 12 13 14 |
# 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 |