Class: Ronin::Core::OutputFormats::OutputFile

Inherits:
OutputFormat
  • Object
show all
Defined in:
lib/ronin/core/output_formats/output_file.rb

Overview

Base class for all output file formats.

Since:

  • 0.2.0

Direct Known Subclasses

CSV, JSON, NDJSON, TXT

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OutputFormat

#<<

Constructor Details

#initialize(io) ⇒ OutputFile

Initializes the output format.

Parameters:

  • io (IO)

    The output stream to write to.

Since:

  • 0.2.0



44
45
46
47
48
# File 'lib/ronin/core/output_formats/output_file.rb', line 44

def initialize(io)
  super()

  @io = io
end

Instance Attribute Details

#ioIO (readonly)

The output stream to write to.

Returns:

  • (IO)

Since:

  • 0.2.0



36
37
38
# File 'lib/ronin/core/output_formats/output_file.rb', line 36

def io
  @io
end

Class Method Details

.open(path) {|output_format| ... } ⇒ OutputFormat

Opens an output file.

Parameters:

  • path (String)

    The path to the new output file.

Yields:

  • (output_format)

    If a block is given, it will be passed the initialized output format. Once the block returns, the output format will automatically be closed.

Yield Parameters:

  • output_format (OutputFormat)

    The newly opened output format.

Returns:

  • (OutputFormat)

    If no block is given, the newly initialized output format will be returned.

Since:

  • 0.2.0



68
69
70
71
72
73
74
75
76
77
# File 'lib/ronin/core/output_formats/output_file.rb', line 68

def self.open(path)
  output = new(File.open(path,'w'))

  if block_given?
    yield output
    output.close
  else
    return output
  end
end

Instance Method Details

#closeObject

Closes the output file.

Since:

  • 0.2.0



82
83
84
# File 'lib/ronin/core/output_formats/output_file.rb', line 82

def close
  @io.close unless @io == $stdout
end