class Procps::PS::CommandBuilder

Builds complete ps shell command before execution.

Public Class Methods

new(ps) click to toggle source
# File lib/procps/ps/command_builder.rb, line 7
def initialize(ps)
  @ps = ps
end

Public Instance Methods

call() click to toggle source
# File lib/procps/ps/command_builder.rb, line 11
def call
  [@ps.bin_path, *modifiers, *options].compact
end
modifiers() click to toggle source
# File lib/procps/ps/command_builder.rb, line 15
def modifiers
  @modifiers ||= @ps.modifiers.size > 0 ? @ps.modifiers.to_a * "" : nil
end
options() click to toggle source
# File lib/procps/ps/command_builder.rb, line 19
def options
  @options ||= begin
    @ps.options.flat_map do |opt, value|
      case value
      when false then nil
      when true  then normalize_option_key(opt)
                 else [normalize_option_key(opt), normalize_option_value(value)]
      end
    end
  end
end

Private Instance Methods

normalize_option_key(opt) click to toggle source
# File lib/procps/ps/command_builder.rb, line 33
def normalize_option_key(opt)
  opt.size == 1 ? "-#{opt}" : "--#{opt}"
end
normalize_option_value(value) click to toggle source
# File lib/procps/ps/command_builder.rb, line 37
def normalize_option_value(value)
  case value
  when Array then value.join(",")
             else value.to_s
  end
end