Class: Ronin::CLI::StringProcessorCommand Private

Inherits:
FileProcessorCommand show all
Defined in:
lib/ronin/cli/string_processor_command.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Similar to FileProcessorCommand, but also accept raw strings via the --string STR option and files via the --file FILE option.

Since:

  • 2.0.0

Defined Under Namespace

Classes: FileValue, StringValue

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from FileProcessorCommand

#open_file, #process_file

Constructor Details

#initialize(**kwargs) ⇒ StringProcessorCommand

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.

Initializes the string processor command.

Parameters:

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

Since:

  • 2.0.0



113
114
115
116
117
# File 'lib/ronin/cli/string_processor_command.rb', line 113

def initialize(**kwargs)
  super(**kwargs)

  @input_values = []
end

Instance Attribute Details

#input_valuesArray<StringValue, FileValue> (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 input values to process.

Returns:

Since:

  • 2.0.0



105
106
107
# File 'lib/ronin/cli/string_processor_command.rb', line 105

def input_values
  @input_values
end

Instance Method Details

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.

Prints a string value.

Parameters:

  • string (String)

    The string value to print.

Since:

  • 2.0.0



164
165
166
# File 'lib/ronin/cli/string_processor_command.rb', line 164

def print_string(string)
  puts string
end

#process_input(input) ⇒ Object

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.

Processes an input stream.

Parameters:

  • input (IO)

    The input stream to read and process.

Since:

  • 2.0.0



148
149
150
151
152
153
154
155
156
# 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) ⇒ String

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.

This method is abstract.

Processes the string.

Parameters:

  • string (String)

    The string to process.

Returns:

  • (String)

    The end result string.

Raises:

  • (NotImplementedError)

Since:

  • 2.0.0



179
180
181
# 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) ⇒ Object

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.

Runs the command.

Parameters:

  • files (Array<String>)

    Additional files to process.

Since:

  • 2.0.0



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# 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