Sha256: 453e46a77ea78d5aac48be89124b9cd14ff56647a9b0cf59b41768afee02c479

Contents?: true

Size: 1.57 KB

Versions: 2

Compression:

Stored size: 1.57 KB

Contents

module HawatelPS
  module Windows
    class ProcInfo < ProcControl
      # Process instance with attributes of that process
      # @param proc_attrs [Hash] attributes of the process
      # @return [void]
      def initialize(proc_attrs)
        @proc_attrs = proc_attrs
        define_attributes(proc_attrs)
      end

      # Make attributes of public.
      # Access to process attribute from an object instance by index of array.
      # @example
      #   p = ProcInfo.new(proc_attrs)
      #   puts p['processid']
      def [](key)
        key = key.to_s.downcase.to_sym if !key.is_a?(Symbol)
        @proc_attrs[key.downcase]
      end

      # Calls the given block once for each element in self, passing that element as a parameter.
      # @param &block
      # @example print all attributes of process
      #   p = ProcInfo.new(proc_attrs)
      #   proc.each {|key, val| puts "#{key} - #{val}"}
      # @return An Enumerator is returned if no block is given.
      def each(&block)
        @proc_attrs.each(&block)
      end

      # @see ProcInfo#define_attributes
      def metaclasses
        class << self; self; end
      end

      private
      # Make attributes of public.
      # Access  to process attribute from an object instance by public method where names of attributes are methods.
      # @example
      #   p = ProcInfo.new(proc_attrs)
      #   puts p.processid
      def define_attributes(hash)
        hash.each_pair do |key, value|
          metaclasses.send(:attr_reader, key.to_sym)
          instance_variable_set("@#{key}", value)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hawatel_ps-0.1.2 lib/hawatel_ps/windows/proc_info.rb
hawatel_ps-0.1.1 lib/hawatel_ps/windows/proc_info.rb