Class: SshDevice::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/brocadesan/device.rb

Overview

This class defines the device response and it should not be manipulated directly Only exception is direct usage of query method which returns instance of this class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prompt) ⇒ Response

initialization method



253
254
255
256
257
258
259
260
# File 'lib/brocadesan/device.rb', line 253

def initialize(prompt) # :nodoc:
  @errors=""
  @data=""
  @parsed = {
   :parsing_position=>nil
  }
  @prompt=prompt
end

Instance Attribute Details

#dataObject

contains output of the command



246
247
248
# File 'lib/brocadesan/device.rb', line 246

def data
  @data
end

#errorsObject

contains errors raised by SSH exec



248
249
250
# File 'lib/brocadesan/device.rb', line 248

def errors
  @errors
end

#parsedObject

contains parsed information after the parse method ran



250
251
252
# File 'lib/brocadesan/device.rb', line 250

def parsed
  @parsed
end

Instance Method Details

#parseObject

Parse the current data and stores result to parsed.

Any class that inherits from this class should override the private parse_line method and store results into parsed hash



273
274
275
276
277
278
279
280
281
# File 'lib/brocadesan/device.rb', line 273

def parse # :nodoc:
  reset if !@parsed.kind_of? Hash
  
  @data.split("\n").each do |line|
    parse_line line
  end
  
  @parsed[:parsing_position]="end"
end

#resetObject

Resets all parsed data



264
265
266
267
268
# File 'lib/brocadesan/device.rb', line 264

def reset # :nodoc:
  @parsed = {
   :parsing_position=>nil
  }
end