ps-ruby 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6cde97732e5357bccc4bdada592dbbd33414e612
4
- data.tar.gz: 45c14906dfaa1d33cacae177df2d0483cac6df00
3
+ metadata.gz: 2aeab74853811588e65ce33b20351cd946bf6cb0
4
+ data.tar.gz: dfa27d8bd46824de4084541547b04d238e16ec04
5
5
  SHA512:
6
- metadata.gz: 28dd310b606ce739a3c9c1adbf04e457826b785f187745c34209bc50cdcc63a2a863e027c19342863afa644f7227f1acd3d358540461425b0aa3f25d5633d32f
7
- data.tar.gz: 35aa1030b27f84b4ea479aefd46cf48a4cdb06bbf9270de548562a121b7838353780d8b47111b95934725ff1f600be3f67eba3d067d9cf12aaa3d29c1f6dbf33
6
+ metadata.gz: eb30a4daf207b107c11c9b493709e17c9e3e1cc433bd9e95dd22e514422cd7892df3995dae0ffc9f90f25ffb95bdca10fe60d43b3e0618b9143843af5ebf4ceb
7
+ data.tar.gz: a3c4a07949071e2bbafeebb4f512c264a329025ab6a707da46d2b8a0e127a1b12407c05e04e0d8af5609182987ff3adc8bc2244873e0d63b854b461c86c1ca00
@@ -7,9 +7,6 @@ puts PS.attrs.to_s
7
7
  # display a simple table
8
8
  PS.find_processes("zsh").simple_display
9
9
 
10
- # find by special attrs
11
- put PS.find_processes("PID", PROCESS_ID)
12
-
13
10
  # Kill all process named 'irb'
14
11
  # PS.find_processes("irb").kill!
15
12
 
@@ -19,4 +16,7 @@ PS.find_processes("chrome").first.alive?
19
16
  # chaining select
20
17
  ms = PS.find_processes("Microsoft")
21
18
  word = ms.find_processes("Word")
22
- ppt = ms.find_processes("PowerPoint")
19
+ ppt = ms.find_processes("PowerPoint")
20
+
21
+ # find by special attrs
22
+ put PS.find_processes("PID", PROCESS_ID)
@@ -6,7 +6,7 @@ class PsProcess < Hash
6
6
  end
7
7
 
8
8
  def alive?
9
- PS.get_all_processes.pick_by_attr("PID").include?(self["PID"])
9
+ PS.get_all_processes.pick_attr("PID").include?(self["PID"])
10
10
  end
11
11
  end
12
12
 
@@ -43,7 +43,7 @@ class PsProcessList < Array
43
43
  PsProcessList.new(self.select{|x| x[attr_name] =~ regex })
44
44
  end
45
45
 
46
- def pick_by_attr(attr_name)
46
+ def pick_attr(attr_name)
47
47
  self.map{|x| x[attr_name] } if PS.attrs.include?(attr_name)
48
48
  end
49
49
 
@@ -76,10 +76,12 @@ module PS
76
76
  def get_all_processes
77
77
  table = raw_aux.split("\n").map{|x| x.split(/\s+/) }
78
78
  attrs = table.shift
79
+ is_percent = ["%CPU", "%MEM"].map{|x| attrs.index(x) }
79
80
  table = table.reduce(PsProcessList.new) {|s, x|
80
81
  if x.size > attrs.size
81
82
  x = x[0..(attrs.size-2)] + [x[(attrs.size-1)..-1].join(" ")]
82
83
  end
84
+ is_percent.each{|k| x[k] = x[k].to_f }
83
85
  s << PsProcess[attrs.zip(x)]
84
86
  }
85
87
  table
@@ -2,6 +2,6 @@ module PS
2
2
  module_function
3
3
 
4
4
  def VERSION
5
- "0.0.3"
5
+ "0.0.4"
6
6
  end
7
7
  end
Binary file
data/readme.md CHANGED
@@ -130,7 +130,7 @@ or
130
130
  ## Get special attribute
131
131
 
132
132
  ```ruby
133
- commands = PS.find_processes("Microsoft").pick_by_attr("COMMAND")
133
+ commands = PS.find_processes("Microsoft").pick_attr("COMMAND")
134
134
  ```
135
135
 
136
136
  ## Kill process
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ps-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - HondaDai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-17 00:00:00.000000000 Z
11
+ date: 2015-04-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -28,6 +28,7 @@ files:
28
28
  - lib/ps-ruby.rb
29
29
  - lib/ps-ruby/ps-ruby.rb
30
30
  - lib/ps-ruby/version.rb
31
+ - ps-ruby-0.0.3.gem
31
32
  - ps-ruby.gemspec
32
33
  - readme.md
33
34
  homepage: https://github.com/HondaDai/ps-ruby