Class: Ronin::CLI::ValueProcessorCommand Private

Inherits:
Command
  • Object
show all
Defined in:
lib/ronin/cli/value_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.

Represents a command which accepts one or more values from the command-line or a file.

Since:

  • 2.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs) ⇒ ValueProcessorCommand

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 command.

Parameters:

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

Since:

  • 2.0.0



49
50
51
52
53
# File 'lib/ronin/cli/value_processor_command.rb', line 49

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

  @files = []
end

Instance Attribute Details

#filesArray<String> (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 additional files to process.

Returns:

  • (Array<String>)

Since:

  • 2.0.0



41
42
43
# File 'lib/ronin/cli/value_processor_command.rb', line 41

def files
  @files
end

Instance Method Details

#process_file(path) ⇒ 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.

Reads and processes each line of the file.

Parameters:

  • path (String)

    The path to the file.

Since:

  • 2.0.0



77
78
79
80
81
# 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) ⇒ 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.

This method is abstract.

Processes an individual value.

Parameters:

  • value (String)

    The string value to process.

Raises:

  • (NotImplementedError)

Since:

  • 2.0.0



91
92
93
# 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) ⇒ 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:

  • values (Array<String>)

    Additional arguments to process.

Since:

  • 2.0.0



61
62
63
64
65
66
67
68
69
# 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