class Ronin::CLI::ValueProcessorCommand
Represents a command which accepts one or more values from the command-line or a file.
Attributes
files[R]
The additional files to process.
@return [Array<String>]
Public Class Methods
new(**kwargs)
click to toggle source
Initializes the command.
@param [Hash{Symbol => Object}] kwargs
Additional keyword arguments.
Calls superclass method
# File lib/ronin/cli/value_processor_command.rb, line 49 def initialize(**kwargs) super(**kwargs) @files = [] end
Public Instance Methods
process_file(path)
click to toggle source
Reads and processes each line of the file.
@param [String] path
The path to the file.
# File lib/ronin/cli/value_processor_command.rb, line 77 def process_file(path) File.open(path) do |file| file.each_line(chomp: true, &method(:process_value)) end end
process_value(value)
click to toggle source
Processes an individual value.
@param [String] value
The string value to process.
@abstract
# File lib/ronin/cli/value_processor_command.rb, line 91 def process_value(value) raise(NotImplementedError,"#{self.class}##{__method__} method was not implemented") end
run(*values)
click to toggle source
Runs the command
@param [Array<String>] values
Additional arguments to process.
# File lib/ronin/cli/value_processor_command.rb, line 61 def run(*values) if (values.empty? && @files.empty?) print_error "must specify one or more arguments, or the --file option" exit(1) end @files.each(&method(:process_file)) values.each(&method(:process_value)) end