Class: PSTree
- Inherits:
-
Object
- Object
- PSTree
- Includes:
- Enumerable
- Defined in:
- lib/pstree.rb,
lib/pstree/version.rb
Defined Under Namespace
Classes: ProcStruct
Constant Summary collapse
- VERSION =
PSTree version
'0.3.0'
- VERSION_ARRAY =
:nodoc:
VERSION.split('.').map(&:to_i)
- VERSION_MAJOR =
:nodoc:
VERSION_ARRAY[0]
- VERSION_MINOR =
:nodoc:
VERSION_ARRAY[1]
- VERSION_BUILD =
:nodoc:
VERSION_ARRAY[2]
Instance Method Summary collapse
- #children_not_zero(last) ⇒ Object
- #children_zero(last) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(root_pid = nil, charset: 'UTF-8') ⇒ PSTree
constructor
A new instance of PSTree.
- #to_s ⇒ Object
Constructor Details
#initialize(root_pid = nil, charset: 'UTF-8') ⇒ PSTree
Returns a new instance of PSTree.
18 19 20 21 |
# File 'lib/pstree.rb', line 18 def initialize(root_pid = nil, charset: 'UTF-8') @charset = charset.to_s.upcase @root_pid = root_pid.to_i end |
Instance Method Details
#children_not_zero(last) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/pstree.rb', line 31 def children_not_zero(last) if @charset == 'UTF-8' last ? '├─ ' : '│ ' else last ? '+- ' : '| ' end end |
#children_zero(last) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/pstree.rb', line 23 def children_zero(last) if @charset == 'UTF-8' last ? '└─ ' : ' ' else last ? '`- ' : ' ' end end |
#each(&block) ⇒ Object
55 56 57 58 59 |
# File 'lib/pstree.rb', line 55 def each(&block) build recurse @root_pid, &block self end |
#to_s ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/pstree.rb', line 39 def to_s build result = '' recurse @root_pid, -> children, last { if children.zero? result << children_zero(last) else result << children_not_zero(last) end } do |ps| result << ps.to_s << "\n" end result end |