class Ronin::CLI::StringProcessorCommand
Similar to {FileProcessorCommand}, but also accept raw strings via the ‘–string STR` option and files via the `–file FILE` option.
Attributes
input_values[R]
The input values to process.
@return [Array<StringValue, FileValue>]
Public Class Methods
new(**kwargs)
click to toggle source
Initializes the string processor command.
@param [Hash{Symbol => Object}] kwargs
Additional keyword arguments.
Calls superclass method
# File lib/ronin/cli/string_processor_command.rb, line 113 def initialize(**kwargs) super(**kwargs) @input_values = [] end
Public Instance Methods
print_string(string)
click to toggle source
Prints a string value.
@param [String] string
The string value to print.
# File lib/ronin/cli/string_processor_command.rb, line 164 def print_string(string) puts string end
process_input(input)
click to toggle source
Processes an input stream.
@param [IO] input
The input stream to read and process.
# File lib/ronin/cli/string_processor_command.rb, line 148 def process_input(input) if options[:multiline] input.each_line(chomp: !options[:keep_newlines]) do |line| print_string(process_string(line)) end else print_string(process_string(input.read)) end end
process_string(string)
click to toggle source
Processes the string.
@param [String] string
The string to process.
@return [String]
The end result string.
@abstract
# File lib/ronin/cli/string_processor_command.rb, line 179 def process_string(string) raise(NotImplementedError,"#{self.class}##{__method__} method was not implemented") end
run(*files)
click to toggle source
Runs the command.
@param [Array<String>] files
Additional files to process.
# File lib/ronin/cli/string_processor_command.rb, line 125 def run(*files) if (files.empty? && @input_values.empty?) process_input(stdin) else @input_values.each do |value| case value when StringValue print_string(process_string(value.string)) when FileValue process_file(value.file) end end files.each(&method(:process_file)) end end