Class: Procps::Column
- Inherits:
-
Object
- Object
- Procps::Column
- Defined in:
- lib/procps/column.rb
Overview
Creates a column object with a typecasting for ps results.
Defined Under Namespace
Classes: Type
Instance Attribute Summary collapse
-
#header ⇒ Object
(also: #to_s)
readonly
Returns the value of attribute header.
Instance Method Summary collapse
-
#call(value) ⇒ Object
Typecasts a raw value.
-
#initialize(header, cast = nil, &cast_block) ⇒ Column
constructor
A new instance of Column.
Constructor Details
#initialize(header, cast = nil, &cast_block) ⇒ Column
Returns a new instance of Column.
7 8 9 10 11 12 |
# File 'lib/procps/column.rb', line 7 def initialize(header, cast = nil, &cast_block) @cast = block_given? ? cast_block : cast raise ArgumentError, "a value of the :cast option must respond to a #call method or be nil" unless @cast.nil? || @cast.respond_to?(:call) @header = header.to_s.freeze freeze end |
Instance Attribute Details
#header ⇒ Object (readonly) Also known as: to_s
Returns the value of attribute header.
4 5 6 |
# File 'lib/procps/column.rb', line 4 def header @header end |
Instance Method Details
#call(value) ⇒ Object
Typecasts a raw value
15 16 17 18 19 20 |
# File 'lib/procps/column.rb', line 15 def call(value) @cast.nil? ? value : @cast.call(value) rescue => e warn e value end |