Class: Procps::Column

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(header, cast = nil, &cast_block) ⇒ Column

Returns a new instance of Column.

Raises:

  • (ArgumentError)


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

#headerObject (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