Class: HawatelPS::Windows::ProcInfo

Inherits:
ProcControl show all
Defined in:
lib/hawatel_ps/windows/proc_info.rb

Instance Method Summary collapse

Methods inherited from ProcControl

#resume, #status, #suspend, #terminate

Constructor Details

#initialize(proc_attrs) ⇒ void

Process instance with attributes of that process

Parameters:

  • proc_attrs (Hash)

    attributes of the process



7
8
9
10
# File 'lib/hawatel_ps/windows/proc_info.rb', line 7

def initialize(proc_attrs)
  @proc_attrs = proc_attrs
  define_attributes(proc_attrs)
end

Instance Method Details

#[](key) ⇒ Object

Make attributes of public. Access to process attribute from an object instance by index of array.

Examples:

p = ProcInfo.new(proc_attrs)
puts p['processid']


17
18
19
20
# File 'lib/hawatel_ps/windows/proc_info.rb', line 17

def [](key)
  key = key.to_s.downcase.to_sym if !key.is_a?(Symbol)
  @proc_attrs[key.downcase]
end

#define_attributes(hash) ⇒ Object (private)

Make attributes of public. Access to process attribute from an object instance by public method where names of attributes are methods.

Examples:

p = ProcInfo.new(proc_attrs)
puts p.processid


43
44
45
46
47
48
# File 'lib/hawatel_ps/windows/proc_info.rb', line 43

def define_attributes(hash)
  hash.each_pair do |key, value|
    metaclasses.send(:attr_reader, key.to_sym)
    instance_variable_set("@#{key}", value)
  end
end

#each(&block) ⇒ Object

Calls the given block once for each element in self, passing that element as a parameter.

Examples:

print all attributes of process

p = ProcInfo.new(proc_attrs)
proc.each {|key, val| puts "#{key} - #{val}"}

Parameters:

  • &block

Returns:

  • An Enumerator is returned if no block is given.



28
29
30
# File 'lib/hawatel_ps/windows/proc_info.rb', line 28

def each(&block)
  @proc_attrs.each(&block)
end

#metaclassesObject

See Also:



33
34
35
# File 'lib/hawatel_ps/windows/proc_info.rb', line 33

def metaclasses
  class << self; self; end
end