Class: Masscan::OutputFile
- Inherits:
-
Object
- Object
- Masscan::OutputFile
- Defined in:
- lib/masscan/output_file.rb
Overview
Constant Summary collapse
- PARSERS =
Mapping of formats to parsers.
{ binary: Parsers::Binary, list: Parsers::List, json: Parsers::JSON, ndjson: Parsers::JSON, # xml: Parsers::XML, }
- FILE_FORMATS =
Mapping of file extensions to formats
{ '.bin' => :binary, '.dat' => :binary, '.txt' => :list, '.list' => :list, '.json' => :json, '.ndjson' => :ndjson, '.xml' => :xml }
Instance Attribute Summary collapse
-
#format ⇒ Symbol
readonly
The format of the output file.
-
#parser ⇒ Parsers::Binary, ...
readonly
private
The parser for the output file format.
-
#path ⇒ String
readonly
The path to the output file.
Class Method Summary collapse
-
.infer_format(path) ⇒ :binary, ...
Infers the format from the output file's extension name.
Instance Method Summary collapse
-
#each {|record| ... } ⇒ Enumerator
Parses the contents of the output file.
-
#initialize(path, format: self.class.infer_format(path)) ⇒ OutputFile
constructor
Initializes the output file.
-
#to_s ⇒ String
Converts the output file to a String.
Constructor Details
#initialize(path, format: self.class.infer_format(path)) ⇒ OutputFile
Initializes the output file.
60 61 62 63 64 65 66 67 |
# File 'lib/masscan/output_file.rb', line 60 def initialize(path, format: self.class.infer_format(path)) @path = path @format = format @parser = PARSERS.fetch(format) do raise(ArgumentError,"unknown format: #{format.inspect}") end end |
Instance Attribute Details
#format ⇒ Symbol (readonly)
The format of the output file.
39 40 41 |
# File 'lib/masscan/output_file.rb', line 39 def format @format end |
#parser ⇒ Parsers::Binary, ... (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The parser for the output file format.
46 47 48 |
# File 'lib/masscan/output_file.rb', line 46 def parser @parser end |
#path ⇒ String (readonly)
The path to the output file.
34 35 36 |
# File 'lib/masscan/output_file.rb', line 34 def path @path end |
Class Method Details
.infer_format(path) ⇒ :binary, ...
Infers the format from the output file's extension name.
99 100 101 102 103 |
# File 'lib/masscan/output_file.rb', line 99 def self.infer_format(path) FILE_FORMATS.fetch(File.extname(path)) do raise(ArgumentError,"could not infer format of #{path}") end end |
Instance Method Details
#each {|record| ... } ⇒ Enumerator
Parses the contents of the output file.
117 118 119 120 121 122 123 |
# File 'lib/masscan/output_file.rb', line 117 def each(&block) return enum_for(__method__) unless block @parser.open(@path) do |file| @parser.parse(file,&block) end end |
#to_s ⇒ String
Converts the output file to a String.
133 134 135 |
# File 'lib/masscan/output_file.rb', line 133 def to_s @path end |