Class: DiskStats::Parser

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/disk-stats.rb

Instance Method Summary collapse

Constructor Details

#initialize(output) ⇒ Parser

Returns a new instance of Parser.



38
39
40
# File 'lib/disk-stats.rb', line 38

def initialize output
  update output
end

Instance Method Details

#[](id) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/disk-stats.rb', line 42

def [] id
  case id
  when Symbol, String
    id = id.to_s
    @devices.find { |d| d.name == id }
  when Fixnum
    @devices[id]
  else
    nil
  end
end

#devicesObject



54
55
56
# File 'lib/disk-stats.rb', line 54

def devices
  @devices.map { |d| d.name.to_sym }
end

#update(new_output) ⇒ Object



58
59
60
# File 'lib/disk-stats.rb', line 58

def update new_output
  parse! new_output.split("\n")
end