Class: Ronin::Core::OutputFormats::JSON
- Inherits:
-
OutputFile
- Object
- OutputFormat
- OutputFile
- Ronin::Core::OutputFormats::JSON
- Defined in:
- lib/ronin/core/output_formats/json.rb
Overview
Represents a JSON (.json
) output format.
Instance Attribute Summary
Attributes inherited from OutputFile
Instance Method Summary collapse
-
#<<(value) ⇒ self
Appends a value to the JSON stream.
-
#close ⇒ Object
Closes the JSON output stream.
-
#initialize(io) ⇒ JSON
constructor
Initializes the JSON output format.
Methods inherited from OutputFile
Constructor Details
#initialize(io) ⇒ JSON
Initializes the JSON output format.
41 42 43 44 45 |
# File 'lib/ronin/core/output_formats/json.rb', line 41 def initialize(io) super(io) @first_value = true end |
Instance Method Details
#<<(value) ⇒ self
Appends a value to the JSON stream.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/ronin/core/output_formats/json.rb', line 58 def <<(value) unless value.respond_to?(:to_json) raise(NotImplementedError,"output value does not define a #to_json method: #{value.inspect}") end if @first_value @io.write("[#{value.to_json}") @first_value = false else @io.write(",#{value.to_json}") end @io.flush return self end |
#close ⇒ Object
Closes the JSON output stream.
77 78 79 80 81 82 83 84 85 |
# File 'lib/ronin/core/output_formats/json.rb', line 77 def close if @first_value @io.write("[]") else @io.write("]") end super end |